swiftswift2swift3ios10deviceid

UIDevice.currentDevice().identifierForVendor!.UUIDString Swift 3 migration


I have the following code in swift 2

let deviceid = UIDevice.currentDevice().identifierForVendor!.UUIDString

This fails to compile. I tried following suggestions from the auto-fix in xCode and I came up with this.

 let deviceid = UIDevice.currentDevice.identifierForVendor!.UUIDString

However it still does not compile. It says value of type 'UUID' has no member UUIDString'


Solution

  • My advice - for these kind of issues - get straight into a playground

    let deviceid = UIDevice.current.identifierForVendor?.uuidString
    

    Playground xCode 8