Add introspection to properties

Originator:davbeck
Number:rdar://20580966 Date Originated:16-Apr-2015 05:54 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 1.2
Classification:Feature (New) Reproducible:Always
 
Swift has an awesome feature that calling Class.myMethodName will return a block that takes an instance that returns a block that calls the method on the instance. This makes for some really clean code that avoids using selectors/strings that could be applied to any class.

It would be nice if this same principal was applied to properties as well. ObjC uses keys and key paths all over the place, but those break as code is refactored without any compiler warning.

Something that worked similar to the following:

Conversation.subject // returns a meta object
Conversation.subject.key // “subject”
Conversation.subject.getter // (Conversation) -> (() -> (String))
Conversation.subject.setter // (Conversation) -> ((String) -> ())

Bonus points for a clean way to replace KVO (that doesn’t crash all the time).

Conversation.subject.addObserver(aConversation, options: nil) {
	// do something when it changes
} // returns an observer meta object that can be used to remove it, i.e. observer.remove()

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!