I get an unexpected result when I append a new object onto an array of objects. The append seems to overwrite the existing object in the array then append itself.
Any thoughts? Or am I missing something really simple.
Here's test code from my playground:
class myRecord {
var firstName: String?
var lastName: String?
}
var myRecords = [myRecord]()
var tempRecord = myRecord()
tempRecord.firstName = "John"
tempRecord.lastName = "Brown"
myRecords.append(tempRecord)
tempRecord.firstName = "Jane"
tempRecord.lastName = "Doe"
myRecords.append(tempRecord)
for x in 0..<myRecords.count {
print(x, "=", myRecords[x].firstName!, myRecords[x].lastName!) }
Console output:
0 = Jane Doe
1 = Jane Doe