Property observers are not called when used recursively on different objects

Originator:garth
Number:rdar://23262331 Date Originated:26-Oct-2015 12:34 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1
Classification:Serious Bug Reproducible:Always
 
This is from the forums (https://forums.developer.apple.com/thread/23190), and it’s not my original discovery, but I wanted to be sure it didn’t get dropped:

When an instance calls the setter of another object of the same class from the property observer of its setter, the property observer of the second class is not called. Here's an example to make it clear:
 
import Foundation  
class TestObject {  
  
    init(name: String) {  
        self.name = name  
    }  
    let name: String  
  
    var otherObject: TestObject?  
  
    var property: String? {  
        didSet {  
            print("Set property of \(name) to \(property)")  
            otherObject?.property = property  
        }  
    }  
}  
let instance1 = TestObject(name: "Instance 1")  
let instance2 = TestObject(name: "Instance 2")  
instance1.otherObject = instance2  
instance1.property = "Test"  
 
The output on the console is
Set property of Instance 1 to Optional("Test")  
 
Though I would expect it to be
Set property of Instance 1 to Optional("Test")  
Set property of Instance 2 to Optional("Test")  
 
Both values are actually set to "Test", but the second time the didSet method is not called.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!