1. CONFIDENTIAL2013 GlobalLogic Inc. Interesting talks from
NSConference 6 by Yuriy Berdnikov
2. 2013 GlobalLogic Inc. CONFIDENTIAL
3. CONFIDENTIAL Key Value Observing (KVO) Core Data Sync with
Ensembles Dont reinvent the wheel. Why ?
4. CONFIDENTIAL Yearly event since 2009 More then 300 people
attended this year Speakers - lead developers, book writers, etc.
Some of them was performed on Apple WWDC. Balance between technical
and UX material NSConference
5. CONFIDENTIAL Key Value Observing
6. CONFIDENTIAL What is KVO ? It provides a way for objects to
get notified when the properties of other objects are changed. One
object observes a key of another object. When the observed object
changes the value of that key, the observer gets notified.
7. CONFIDENTIAL Subscribing
8. CONFIDENTIAL Responding
9. CONFIDENTIAL So how does that work, not needing any code in
the observed object?
10. CONFIDENTIAL isa-swizzling It creates a brand new class at
runtime that subclasses your class It overrides the set methods for
any observed keys It switches out the isa pointer of your
object
11. CONFIDENTIAL Sample
12. CONFIDENTIAL @interface TestClass : NSObject { int x; int
y; int z; } @property int x; @property int y; @property int z;
@end
13. CONFIDENTIAL static NSArray *ClassMethodNames(Class c) {
NSMutableArray *array = [NSMutableArray array]; unsigned int
methodCount = 0; Method *methodList = class_copyMethodList(c,
&methodCount); for (unsigned int i = 0; i < methodCount;
i++) [array addObject:
NSStringFromSelector(method_getName(methodList[i]))];
free(methodList); return array; }
16. CONFIDENTIAL Running the Code control: NSObject class
TestClass libobjc class TestClass implements methods x: NSObject
class TestClass libobjc class NSKVONotifying_TestClass implements
methods y: NSObject class TestClass libobjc class
NSKVONotifying_TestClass implements methods xy: NSObject class
TestClass libobjc class NSKVONotifying_TestClass implements
methods
17. CONFIDENTIAL Core Data Sync with Ensembles
18. CONFIDENTIAL Elements of Sync Identifying corresponding
objects across stores Determining what has changed since the last
sync Resolving conflicts due to concurrent changes
19. CONFIDENTIAL Ensembles Requires minimal changes to existing
code Backend agnostic Eventual consistency of data across client
devices Conflict resolution