Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

IOS KVC

No description
by

WeiJun Lin

on 21 March 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of IOS KVC

KVC
value types and nil
Property values are always of type
id
(reference type)
KVC Collection
What is it?
Access properties by name:
How it works
NSKeyValueCoding
(informal) protocol
Accessor lookup
Search for a public accessor ('
getLastName
' or '
lastName
')
IOS KVC
Every class essentially becomes a dictionary
Not a 'trick'. This is fundamental Cocoa programming.
Implemented by
NSObject
NSKeyValueCoding.h
If not found, search for a private accessor method based on key ('
_getLastName
' or '
_lastName
').
If not found' search for an instance variable (
_lastName
or
lastName
)
If not found, invoke
valueForUndefinedKey:

structs ->
NSValue
numbers ->
NSNumber
You should implement
setNilValueForKey:
KVC NSDictionary
NSDictionary
has a custom implementation of KVC that attempts to match keys against keys in the dictionary.
NSDictionary *dict = @{
@"name"
:
@"Dream"
};
[dictionary setValue:
@"Yume"
forKey:
@"name"
]
Key Paths
Like file paths (/usr/local/bin)
Used to traverse an object graph: "document.header.title"
valueForKeyPath:
,
setValue:forKeyPath:
Warning!
: you cannot pass a keyPath if the selector is just '
forKey
:' only to '
forKeyPath:
'
KVC Array
No native support. You cannot pass indexes in key paths:

valueForKeyPath:@"order.items[1].price"
Ask an array for a key, the array will ask all its elements and return an array of the resulting values.
[person name]
[person valueForKey:
@"name"
]
[person setName:
@"Yume"
]
[person setValue:
@"Yume"

ForKey:
@"name"
]
@avg, @count, @max, @min, @sum
Collection Method
[@[@1,@2,@3] valueForKey:
@"@count"
]
KVC
Collection Operators
[NSObject self]
@distinctUnionOfArrays, @distinctUnionOfObjects, @distinctUnionOfSets, @unionOfArrays,
@unionOfObjects,
@unionOfSets
[@[@1,@2,@3] valueForKeyPath:
@"@max.self"
]
Content Method
[@[@1,@2,@3] valueForKey:
@"intValue"
]
[array valueForKeyPath:@"@times.aaa.bbb"]
KVC
Custom Collections Operators
Format :
- (
id
) _<operator>ForKeyPath:(NSString*)keyPath
Example :
- (
id
) _timesForKeyPath:(NSString*)keyPath
@times
@"aaa.bbb"
Reference :
http://bou.io/KVCCustomOperators.html#fn:3
http://www.slideshare.net/sergio.acosta/intro-to-cocoa-kvckvo-and-bindings-presentation

Thank you for your attention!!
Full transcript