mobile techtalk - interesting talks from nsconference 6
DESCRIPTION
This presentation contains new ideas in the field of mobile software development, discussed at NSConference 6 – one of the most popular mobile conferences in Europe. Presentation by Yuriy Berdnikov, leading engineer, GlobalLogic. Mobile TechTalk, Lviv, 2014. More details - www.globallogic.com.ua/press-releases/mobile-techtalk-lviv/TRANSCRIPT
- 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; }
- 14. CONFIDENTIAL static void PrintDescription(NSString *name, id obj) { NSString *str = [NSString stringWithFormat: @"%@: %@nt NSObject class %snt libobjc class %snt implements methods ", name, obj, class_getName([obj class]), class_getName(obj->isa), [ClassMethodNames(obj->isa) componentsJoinedByString:@", ]]; printf("%sn", [str UTF8String]); }
- 15. CONFIDENTIAL int main(int argc, char **argv) { [NSAutoreleasePool new]; TestClass *x = [[TestClass alloc] init]; TestClass *y = [[TestClass alloc] init]; TestClass *xy = [[TestClass alloc] init]; TestClass *control = [[TestClass alloc] init]; [x addObserver:x forKeyPath:@"x" options:0 context:NULL]; [xy addObserver:xy forKeyPath:@"x" options:0 context:NULL]; [y addObserver:y forKeyPath:@"y" options:0 context:NULL]; [xy addObserver:xy forKeyPath:@"y" options:0 context:NULL]; PrintDescription(@"control", control); PrintDescription(@"x", x); PrintDescription(@"y", y); PrintDescription(@"xy", xy); return 0; }
- 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
- 20. CONFIDENTIAL github.com/drewmccormack/ensembles ensembles.io
- 21. CONFIDENTIAL Dont reinvent the wheel
- 22. CONFIDENTIAL Why ? Old code sucks 1000 solutions for 1000 problems, but you only need 1 Maintenance
- 23. CONFIDENTIAL
- 24. CONFIDENTIAL There is a good code! Manage risks Learn technologies that 3rd party code uses Write own frameworks
- 25. CONFIDENTIAL2013 GlobalLogic Inc. Q&A
- 26. CONFIDENTIAL2013 GlobalLogic Inc. Thank you