Skip to content
rcloud edited this page Jun 10, 2012 · 3 revisions

#iOS Programming ##Classes

##Key-Value Coding Fundamentals

  • A key is a string taht identifies a specific property of an object. a key corresponds to the name of an accessor method or instance variable in the receiving object. Keys must use ASCII encoding begin with a lowercase letter and may not contain whitespace.
  • a key path is a string of dot separated keys taht is used to specify a sequence of objects to traverse. the property of the first key in the sequence is relative to the receiver.
  • subsequent keys evaluate relative to the value of the previous property.
    ###Getting Attribute Values using KVC
  • the method valueForKey: returns the value for the specified key, relative to the receiver. If there is no accessor or instance variable for the specified key, then the receiver sends itself a valueFoUndefinedKey method.
  • the default implementation of that raises an NSUndefinedKeyexception
  • valueForKeyPath returns the value for the speciifed path key relative to the receiver
  • also dictionaryWithValuesForKeys

##Setting Attributes using Key Value Coding

  • the method setValue:forKey: sets the value fo the specified key relative to the receiver to the provide value. The default implementation of this automatically unwraps NSValue objects that represent scalars and structs and assigns them to the property.
  • also setValue:forKeyPath:
  • setValuesForKeysWithDictionary:

Clone this wiki locally