swift - willSet/didSet called on a container's stored property x when setting a property of x -


i observed behaviour don't quite understand. when executing code in playground:

protocol testp {     var notes: string { set } }  class testc: testp {     var notes: string = "" }  class testcontainer {     var test: testp! = testc() {         willset {             print("willset")         }         didset {             print("didset")         }     } }  var testcontainer = testcontainer()  // triggers willset+didset call on testcontainer's  // stored property: testcontainer.test.notes = "x" 

the willset , didset blocks called though property not being set.

on other hand, if change protocol of type class follow

protocol testp: class {     var notes: string { set } } 

then result expect (i.e. no call willset/didset).

what reason behaviour?

i run on xcode 7.3.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo