I have following code working in a playground. The didSet observer is working as expected.
struct itemStruct {
var name : String = "" {
didSet (newName) {
didSetNameTest(name)
}
}
}
func didSetNameTest (name : String) {
println("didSet itemStruct: \(name)")
}
var item = itemStruct()
item.name = "test"
If I move the code within a class I get an compiler error:
class itemClass {
struct classItemStruct{
var name : String = "" {
didSet(newName) {
didSetClassNameTest(name)
}
}
}
func didSetClassNameTest(name:String) {
println("didSet itemClass: \(name)")
}
var structItem = classItemStruct()
}
var cItem = itemClass()
cItem.structItem.name = "Test"
Error: Cannot invoke 'didSelectClassNameTest' with an argument list of type '(String)'
.
All code could be copied in playground.