UUID always nil

Hi,


In my Mac OS app I'm trying to create an UUID from a string

the code is taken straight from the documentation but it returns nil every time


import Foundation

let test1  = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F") // Returns nil
let test2 = UUID() //Works fine


it works fine in a playground but not in my app.


any ideas?

Accepted Reply

As far as I tried in an actual app, both `test1` and `test2` always returned non-nil value.


How have you checked `test1` is nil in your app?

Used `print` ? Varible values shown in Xcode debugger may be wrong.

Replies

As far as I tried in an actual app, both `test1` and `test2` always returned non-nil value.


How have you checked `test1` is nil in your app?

Used `print` ? Varible values shown in Xcode debugger may be wrong.

Tested in an app


        let test1  = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")
        let test2 = UUID() //Works fine
        if test1 == nil { print("test1 nil")} else { print("test1 not nil")}
        if test2 == nil { print("test2 nil")} else { print("test2 not nil")}

Got

test1 not nil

test2 not nil


Tested both in MacOS and iOS app

Your are right :-)


The rest of the original code surrounding these UUID's made me believe that they where the cause of my app crashing.

Printed them to the console and they are in fact OK.

Values in the debugger seem not reliable (whats up with that???)


Thank u so much :-)

Is optimization turned on?

That can make variable values unavailable.