4 Replies
      Latest reply on Jan 8, 2020 9:41 AM by jlilest002
      TheMisfit Level 1 Level 1 (0 points)



        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?

        • Re: UUID always nil
          OOPer Level 8 Level 8 (5,535 points)

          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.

          • Re: UUID always nil
            Claude31 Level 8 Level 8 (7,845 points)

            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")}


            test1 not nil

            test2 not nil


            Tested both in MacOS and iOS app