• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting started with Cocoa Bindings in My Project?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Getting started with Cocoa Bindings in My Project? (From: Alex Hall <email@hidden>)
 >Re: Getting started with Cocoa Bindings in My Project? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Swift generics, circular type declarations, and segfaults, oh my!
  • Next by Date: NSXMLDocument - XSLT version
  • Previous by thread: Re: Getting started with Cocoa Bindings in My Project?
  • Next by thread: Re: Getting started with Cocoa Bindings in My Project?
  • Index(es):
    • Date
    • Thread