> On Jul 7, 2017, at 22:50, Marco S Hyman via swift-users 
> <swift-users@swift.org> wrote:
> 
> 
>> On Jul 7, 2017, at 9:48 PM, Zhao Xin <owe...@gmail.com> wrote:
>> 
>> Thank you very much Marco. But What is  “outside of an initializer” really 
>> bothers me. **Both** `func bar(keysAndValues:Dictionary<String, String>)` 
>> works now. **Are they really outside ?**
> 
> Uhhh, that is certainly not the results I’d have expected.  Perhaps one of 
> the  swift language lawyers can explain.

The goal is that once the initializer is completed all accesses will go through 
the setter and therefore trigger willSet/didSet behavior. Since a local 
function can be assigned to a property or something and get called later, it 
has to go through the setter as well. So the rules only apply to what's 
directly in the body of the initializer, not anything nested. (This includes 
closures, even.) It might be worth a bug against us at Apple to make this more 
explicit in the documentation, https://bugreport.apple.com 
<https://bugreport.apple.com/>.

We also have a bug where 'defer' can trigger willSet and didSet behavior as 
well, SR-1437 <https://bugs.swift.org/browse/SR-1437>. But that really is just 
a bug.

Jordan

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to