CONFIDENTIAL©2013 GlobalLogic Inc.
Interesting talks from
NSConference 6
by Yuriy Berdnikov
©2013 GlobalLogic Inc. CONFIDENTIAL
CONFIDENTIAL
Key Value Observing (KVO)
Core Data Sync with Ensembles
“Don’t reinvent the wheel”. Why ?
CONFIDENTIAL
 Yearly event since 2009
 More then 300 people attended this year
 Speakers - lead developers, book writer...
CONFIDENTIAL
Key Value Observing
CONFIDENTIAL
What is KVO ?
It provides a way for objects to get notified when the properties of other
objects are changed....
CONFIDENTIAL
Subscribing
CONFIDENTIAL
Responding
CONFIDENTIAL
So how does that work, not needing any
code in the observed object?
CONFIDENTIAL
isa-swizzling
• It creates a brand new class at runtime that
subclasses your class
• It overrides the set met...
CONFIDENTIAL
Sample
CONFIDENTIAL
@interface TestClass : NSObject
{
int x;
int y;
int z;
}
@property int x;
@property int y;
@property int z;
@...
CONFIDENTIAL
static NSArray *ClassMethodNames(Class c)
{
NSMutableArray *array = [NSMutableArray array];
unsigned int meth...
CONFIDENTIAL
static void PrintDescription(NSString *name, id obj)
{
NSString *str = [NSString stringWithFormat:
@"%@: %@nt...
CONFIDENTIAL
int main(int argc, char **argv)
{
[NSAutoreleasePool new];
TestClass *x = [[TestClass alloc] init];
TestClass...
CONFIDENTIAL
Running the Code
control: <TestClass: 0x104b20>
NSObject class TestClass
libobjc class TestClass
implements m...
CONFIDENTIAL
Core Data Sync with Ensembles
CONFIDENTIAL
Elements of Sync
• Identifying corresponding objects across stores
• Determining what has changed since the l...
CONFIDENTIAL
Ensembles
• Requires minimal changes to existing code
• Backend agnostic
• Eventual consistency of data acros...
CONFIDENTIAL
• github.com/drewmccormack/ensembles
• ensembles.io
CONFIDENTIAL
“Don’t reinvent the wheel”
CONFIDENTIAL
Why ?
• Old code sucks
• 1000 solutions for 1000 problems, but you only
need 1
• Maintenance
CONFIDENTIAL
CONFIDENTIAL
• There is a good code!
• Manage risks
• Learn technologies that 3rd party code uses
• Write own frameworks
CONFIDENTIAL©2013 GlobalLogic Inc.
Q&A
CONFIDENTIAL©2013 GlobalLogic Inc.
Thank you
Upcoming SlideShare
Loading in …5
×

Mobile TechTalk - Interesting talks from NSConference 6

574 views

Published on

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/

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
574
On SlideShare
0
From Embeds
0
Number of Embeds
228
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mobile TechTalk - Interesting talks from NSConference 6

  1. 1. CONFIDENTIAL©2013 GlobalLogic Inc. Interesting talks from NSConference 6 by Yuriy Berdnikov
  2. 2. ©2013 GlobalLogic Inc. CONFIDENTIAL
  3. 3. CONFIDENTIAL Key Value Observing (KVO) Core Data Sync with Ensembles “Don’t reinvent the wheel”. Why ?
  4. 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. 5. CONFIDENTIAL Key Value Observing
  6. 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. 7. CONFIDENTIAL Subscribing
  8. 8. CONFIDENTIAL Responding
  9. 9. CONFIDENTIAL So how does that work, not needing any code in the observed object?
  10. 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. 11. CONFIDENTIAL Sample
  12. 12. CONFIDENTIAL @interface TestClass : NSObject { int x; int y; int z; } @property int x; @property int y; @property int z; @end
  13. 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. 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. 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. 16. CONFIDENTIAL Running the Code control: <TestClass: 0x104b20> NSObject class TestClass libobjc class TestClass implements methods <setX:, x, setY:, y, setZ:, z> x: <TestClass: 0x103280> NSObject class TestClass libobjc class NSKVONotifying_TestClass implements methods <setY:, setX:, class, dealloc, _isKVOA> y: <TestClass: 0x104b00> NSObject class TestClass libobjc class NSKVONotifying_TestClass implements methods <setY:, setX:, class, dealloc, _isKVOA> xy: <TestClass: 0x104b10> NSObject class TestClass libobjc class NSKVONotifying_TestClass implements methods <setY:, setX:, class, dealloc, _isKVOA>
  17. 17. CONFIDENTIAL Core Data Sync with Ensembles
  18. 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. 19. CONFIDENTIAL Ensembles • Requires minimal changes to existing code • Backend agnostic • Eventual consistency of data across client devices • Conflict resolution
  20. 20. CONFIDENTIAL • github.com/drewmccormack/ensembles • ensembles.io
  21. 21. CONFIDENTIAL “Don’t reinvent the wheel”
  22. 22. CONFIDENTIAL Why ? • Old code sucks • 1000 solutions for 1000 problems, but you only need 1 • Maintenance
  23. 23. CONFIDENTIAL
  24. 24. CONFIDENTIAL • There is a good code! • Manage risks • Learn technologies that 3rd party code uses • Write own frameworks
  25. 25. CONFIDENTIAL©2013 GlobalLogic Inc. Q&A
  26. 26. CONFIDENTIAL©2013 GlobalLogic Inc. Thank you

×