We're experiencing some weird issues with the Xcode debugger reporting incorrect values for properties in certain circumstances. Here's a tiny concrete example that illusrates the problem (it works for both MacOS and iOS)...
Say you have a Protocol lke this...
import Foundation
protocol MyProtocol {
func aProtocolFunction()
}
And a Struct like this, which conforms to the Protocol, like this...
import Foundation
struct MyStruct: MyProtocol {
var property1 = [Float]()
var property2 = [Float]()
var property3 = [Float]()
var property4 = [Float]()
func aProtocolFunction() {
//This function doesn't have to do anything
}
}
Now, if you write some code that uses the above struct and protocol lke this, and add a break point on the line which says, "add a break point on this line" the issue we have can be observed....
var myStruct = MyStruct()
var myArrayOfProtocolConformingThings = [MyProtocol]()
myStruct.property1 = [1.0]
myStruct.property2 = [1.0, 2.0]
myStruct.property3 = [1.0, 2.0, 3.0]
myStruct.property4 = [1.0, 2.0, 3.0, 4.0]
myArrayOfProtocolConformingThings.append(myStruct)
print("Add a break point on this line")
You find that when you inspect the contents of the myArrayOfProtocolConformingThings array in the Xcode debugger, it reports completely the wrong contents for myArrayOfProtocolConformingThings[0]. Specifically, the values for property1, property2, property3 and property4 are all reported incorrectly. The debugger says that:
- property1 is an empty array
- property2 is an empty array
- property3 shows the contents of property1
- property4 shows the contents of property2
Does anyone know what's going on here? This kind of issue is making it really hard to sort out some problems in our code. We think some of the issues might be Swift compiler bugs (as well as our own bugs!), but it's really hard to know when the debugger gets things so wrong.