objective-c to swift

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

objective-c to swift

Ismail El-Habbash
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


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: objective-c to swift

Sam Stigler
Have you tried putting curly brackets around the body of the "if" statement? Which error specifically are you getting?

Sam

On Mar 30, 2015, at 11:36 AM, Ismail El-Habbash <[hidden email]> wrote:

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


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/93AA3389-9C71-4DAB-8F31-47E189F061F5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: objective-c to swift

Ismail El-Habbash
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

On Monday, March 30, 2015 at 6:03:18 PM UTC+1, Sam Stigler wrote:
Have you tried putting curly brackets around the body of the "if" statement? Which error specifically are you getting?

Sam

On Mar 30, 2015, at 11:36 AM, Ismail El-Habbash <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UH-2M-fQklIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ismaile...@...> wrote:

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


--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="UH-2M-fQklIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-languag...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="UH-2M-fQklIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-l...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/swift-language/fed763aa-d05e-453a-86f7-64fc0afb625a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/swift-language/fed763aa-d05e-453a-86f7-64fc0afb625a%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/swift-language/fed763aa-d05e-453a-86f7-64fc0afb625a%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/swift-language/fed763aa-d05e-453a-86f7-64fc0afb625a%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/405a1924-63b4-48e9-b5b5-7b8e8bcb7df8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: objective-c to swift

Marco S Hyman
In reply to this post by Ismail El-Habbash
> 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)
}



--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/8E0BA115-3050-4952-A57F-DDB1C28CACCA%40snafu.org.
For more options, visit https://groups.google.com/d/optout.