Going Down the Core Data Rabbit Hole
-
Upload
aaron-douglas -
Category
Technology
-
view
1.931 -
download
2
description
Transcript of Going Down the Core Data Rabbit Hole
- 1.Going Down the Core Data Rabbit Hole Aaron Douglas @astralbodies 1Tuesday, August 13, 13
2. Platinum Sponsors Gold Sponsors 2Tuesday, August 13, 13 3. Who am I? Aaron Douglas @astralbodies Automattic (WordPress) iOS Developer / Android (a little) Previous Life == Enterprise Java Developer 3Tuesday, August 13, 13 4. Who are you? iOS Developers? Tinkerers? Anyone use SQLite before? How about Core Data? 4Tuesday, August 13, 13 5. SQLite is GREAT Self-contained Server-less Nearly zero conguration Transactional Written in C / Super portable 5Tuesday, August 13, 13 6. SQLite meh Written in C No ARC Foundation wrappers Lots of boilerplate Code Room for archive/unarchive mapping errors 6Tuesday, August 13, 13 7. Why Core Data? Lets Step Back 7Tuesday, August 13, 13 8. ORM Object Relational Mapping Maps tables to real objects Persisting is relatively easy Less code (usually) Hibernate, Entity Framework, Ibatis 8Tuesday, August 13, 13 9. Why Core Data? In Appleland for many years - OS X Tiger, iPhone OS 3.0 Xcode visual designer Validation Migration Persist anywhere - SQLite, XML, memory 9Tuesday, August 13, 13 10. Core Data Topics Main moving parts Managed Object Managed Object Model & Context Persistent Store Persistent Store Coordinator Fetch Requests 10Tuesday, August 13, 13 11. Managed Objects 11Tuesday, August 13, 13 12. Models NSManagedObjectModel Designer in Xcode Through code 12Tuesday, August 13, 13 13. Managed Objects objectID NSString, NSDate, NSNumber Validation Undo Management Faults Refresh 13Tuesday, August 13, 13 14. Object Contexts Scratchpad Each object associated to single context Objects are not transferrable Nested contexts 14Tuesday, August 13, 13 15. Operations object = [NSManagedObject insertNewObjectForEntityForName:@Speak er inManagedObjectContext:context]; [context deleteObject:object]; 15Tuesday, August 13, 13 16. Relationships NSSet NSOrderedSet Deletes 16Tuesday, August 13, 13 17. Finding Objects NSFetchRequest NSPredicate NSSortDescriptor 17Tuesday, August 13, 13 18. Fetching Example NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Appointment" inManagedObjectContext:context]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; request.entity = entityDescription; NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"(date >= %@)", startDate]; NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"(date = %@)", startDate]; NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"(date