> On Sep 6, 2015, at 1:14 PM, Ken Thomases <k...@codeweavers.com> 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com