Re: Getting started with Cocoa Bindings in My Project?
Re: Getting started with Cocoa Bindings in My Project?
- Subject: Re: Getting started with Cocoa Bindings in My Project?
- From: Charles Srstka <email@hidden>
- Date: Sun, 06 Sep 2015 14:27:55 -0500
> On Sep 6, 2015, at 1:14 PM, Ken Thomases <email@hidden> wrote:
>
> The easiest approach is to provided a class method named keyPathsForValuesAffecting<NameOfComputedProperty> which returns a set of key paths for the input properties. In Objective-C, this might look like:
>
> + (NSSet*) keyPathsForValuesAffectingMyComputedProperty
> {
> return [NSSet setWithObjects:@"inputProperty1", "otherInputProperty", nil];
> }
>
> In Swift, I expect this needs to be "dynamic", too.
Here’s the template for the keyPathsForValues… method in Swift:
private dynamic class func keyPathsForValuesAffecting<#name#>() -> Set<String> {
return [<#dependency#>]
}
Note that in Objective-C, Xcode will autocomplete this method for you, but in Swift, it won’t. This gets fun when you realize that the above method is pretty easy to mistype and/or misremember, so what I suggest you do is copy and paste the code above into an Xcode code snippet, and give a keyword you can type that will autocomplete to it (I use ‘keyPaths’, so every time I start typing keyPaths, it’ll autocomplete to the above. It’s pretty helpful).
The “private” is so that it doesn’t show up in the public interface or generated Obj-C headers, because it’s pretty much unnecessary clutter there. The only code that will be calling this method is the KVC system, and it’ll be using -respondsToSelector: rather than the public interface anyway.
Charles
_______________________________________________
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