April 2015
Intermediate to advanced
556 pages
17h 47m
English
In some cases a value may be dependent on another. For example, if you have a Person class with a computed property fullName that is dependent on the properties firstName and lastName, wouldn’t it be nice if observers of fullName could be notified when either firstName or lastName changes? KVO’s designers thought so, too, which is why they implemented a convention for defining dependent keys.
To define a key’s dependencies you must implement a specially named class method which returns a Set of key paths. In the example above you would implement keyPathsForValuesAffectingFullName():
class Person { dynamic var firstName = "" dynamic var lastName = "" dynamic var fullName { return "\(firstName) ...Read now
Unlock full access