Going Down the Core Data Rabbit Hole

download Going Down the Core Data Rabbit Hole

If you can't read please download the document

description

Core Data is a great framework that Apple provides to help persist data in your applications. If you have familiarity with other persistence frameworks like N/Hibernate and Entity Framework then you may feel right at home with Core Data! Using SQLite directly can be a real pain, especially if you have little to no C experience. Core Data lets you ignore the actual store used and gives a great interface to make saving information a little more straightforward. This session will cover the basics and intermediate topics of Core Data and some of the bigger gotchas that Apple's Documentation doesn't necessarily call out. I'll give some of the tips and tricks I've learned over the years of using Core Data so that you have less pain to get started. Core Data is certainly not the most friendly of APIs, but once you learn it, you'll use it all the time.

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