Weird Debugging Behavior with Struct That Contains a UUID

2020-02-15 ios swift xcode11

Consider this struct:

struct test
{
    var id:UUID = UUID()
    var name:String = ""
}

When executing the following line of code:

var myTest : test?

The debugger correctly shows myTest = nil

Then I execute:

myTest = test()

The debugger still shows MyTest = nil

If I remove the id variable from the struct, the debugger correctly shows a value for myTest.

It seems that whenever I have a UUID in the struct it does this.

Is this a bug in Xcode11, or am I missing something?

Here is a screenshot after declaring myTest showing it nil as expected:

enter image description here

Here is a screenshot after setting myTest to test(), and printing it. You can see that the print shows the initialized structure, but the debug window still shows myTest as nil:

enter image description here

Answers

I am not sure why you think this is unexpected behaviour. If you were to have a struct like so:

struct test {
    var name: String = ""
}

By doing so

var myTest: test?

myTest = test()

print(myTest)

result: Optional(__lldb_expr_7.test(name: ""))

Even if you were to add in a UUID like so :

struct test {
    var id: UUID = UUID(uuid: UUID_NULL)
    var name: String = ""
}

and did the same thing

var myTest: test?
myTest = test()
print(myTest)

Result: Optional(__lldb_expr_9.test(id: 00000000-0000-0000-0000-000000000000, name: ""))

You are still given the structure

if you had a struct like so

struct test {
    var id: UUID = UUID(uuid: UUID_NULL)
    var name: String = ""
    var lastName: String = ""
}

and still did the same thing...

var myTest: test?

myTest = test()

print(myTest)

result: Optional(__lldb_expr_11.test(id: 00000000-0000-0000-0000-000000000000, name: "", lastName: ""))

you are still given back results...

The results are all nill or empty strings as defined in the struct...

we can then append to the struct like so

var myTest: test?

myTest = test(id: some_UUID_Number_Here, name: "Jack", lastName: "Sparrow")

print(myTest as Any)

result: Optional(__lldb_expr_3.test(id: BBDD802E-8976-4D93-A6E2-1D43442EA9CD, name: "Jack", lastName: "Sparrow"))

Hope this helps...

Related