objective-c to swift

31 views
Skip to first unread message

Ismail El-Habbash

unread,
Mar 30, 2015, 12:36:21 PM3/30/15
to swift-l...@googlegroups.com
Im trying to convert these lines of code to swift , but its not working with me .

NSInteger types;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.f) 
    types = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
Here is my swift implementation of it but it isn't working  ,as i need types to be NSInteger for an api I'm using.

 

        if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0

            types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound


Sam Stigler

unread,
Mar 30, 2015, 1:03:18 PM3/30/15
to Ismail El-Habbash, swift-l...@googlegroups.com
Have you tried putting curly brackets around the body of the "if" statement? Which error specifically are you getting?

Sam
--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.
To post to this group, send email to swift-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/fed763aa-d05e-453a-86f7-64fc0afb625a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ismail El-Habbash

unread,
Mar 30, 2015, 1:26:02 PM3/30/15
to swift-l...@googlegroups.com, ismaile...@gmail.com
Yes  I put curly brackets around it , 
The error I'm getting is  UIUserNotificationType is not convertible to Bool , 

This code works perfectly with objective c so I really don't know whats going on.

Thanks

Marco S Hyman

unread,
Mar 30, 2015, 2:28:50 PM3/30/15
to Ismail El-Habbash, swift-l...@googlegroups.com
> Here is my swift implementation of it but it isn't working ,as i need types to be NSInteger for an api I'm using.
>
>
> if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0
> types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound


I think you need to get the raw value (a UInt) and convert that to an
NSInteger. This code seems to work in a playgound.

var intTypes: NSInteger

if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 {
let types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
intTypes = NSInteger(types.rawValue)
}



Reply all
Reply to author
Forward
0 new messages