Re: Bindings in Swift
Re: Bindings in Swift
- Subject: Re: Bindings in Swift
- From: Roland King <email@hidden>
- Date: Sun, 10 Aug 2014 21:46:02 +0800
>
>> if you write such a property in Swift and mark it only @objc then it's quite possible Swift will call the original, unswizzled methods, and you won't get your notification .. because objc_MsgSend may not be used
>
> Yes, I suppose if Swift decided to use a direct call, it would call the wrong thing, but not because of swizzling, since KVO doesn’t swizzle. Instead, it dynamically changes the class of your object to a synthetic class with a method that overrides your setter. So, the error in Swift’s “reasoning” would be that the method wasn’t overridden when it really was.
>
Some nice person pointed me to the documentation which says in black and white (and blue and a bit of purple and green) that you need dynamic for KVO-able Swift properties. And I believe my thought process finally got to the bottom of the well and I understand what the differences are between dynamic, @objc and not having anything at all.
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html#//apple_ref/doc/uid/TP40014216-CH7-XID_9
I still suck at Swift and when I need to knock something up to test in 10 minutes find myself reaching for the trusty ObjC toolbelt. I suspect I need 2 projects to get anywhere, the first one to do it all badly wrong and write Swift which is just wrapped ObjC and the second one to actually start thinking in the language.
And if anyone thinks Swift is all simplicity and scripty loveliness I came across this StackOverflow question and answer today. It will be a while before I entirely understand it, it will be a long while before I could attempt to reproduce it.
http://stackoverflow.com/questions/24070873/error-using-associated-types-and-generics/24845414#24845414
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden