8

The following code doesn't work anymore in Beta 5.

let device = UIDevice.currentDevice()
if (device.systemVersion.bridgeToObjectiveC().floatValue < 8.0) {
    [skipped]
}    

Also, it's not possible to downcast a string to float.

let device = UIDevice.currentDevice()
let version: Float = device.systemVersion as Float

The snippet above returns the 'String' is not convertible to 'Float' error.

Any ideas how should we test the OS version now? Thanks.

2 Answers 2

7

floatValue is a method of NSString.
Since bridgeToObjectiveC() is no longer available with Xcode 6 Beta 5, you can use the as operator to cast your Swift String to NSString:

(device.systemVersion as NSString).floatValue 
Sign up to request clarification or add additional context in comments.

2 Comments

Just out of interest, do you know why we no longer have bridgeToObjC?
No idea but probably because in most cases one can achieve the same using the built-in type casting keyword. So bridgeToObjectiveC() would introduce redundancy and worse legibility.
2

I am using this approach for now

("1.3" as NSString).floatValue

1 Comment

This wont work for ("17.4.6" as NSString).floatValue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.