SlideShare a Scribd company logo
Pulling back the curtain on
         Core Data
             Chris Mar
         Spree Commerce
          http://cmar.me
Chris Mar

• Spree Commerce

• iOS and Rails Developer

• @cmar

• Grassy Knoll Apps - Redskins
  Radar
Goal
Pull back the curtain on Core Data so
 you will use it on your next project
             without fear!




(we’ll focus on concepts, not a tutorial)
Core Data

• Object Relational Mapping
• Gives you access to a database without using sql
  or parsing results

• Cocoa API with XCode tooling to assist you

• Hibernate for Java, ActiveRecord for Rails
Storage Types
• SQLite Database

• XML

• In-Memory




              we’ll focus on SQLite
NSManagedObject
•   Row from the database

•   Key-Value coding for fields

•   Optionally subclass

•   Fetched from NSManagedObjectContext



                    [employee valueForKey:@"name"];
Managed Objects
    object1                                  object2




    object1                                  object2




               NSManagedObjectContext

              NSPersistentStoreCoordinator


                NSManagedObjectModel




    object1


                    SQLite Database
FetchRequest for
                      NSManagedObjects
NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setEntity:[NSEntityDescription entityForName:@"Order"
                 inManagedObjectContext:self.managedObjectContext]];

[request setPredicate:[NSPredicate
                predicateWithFormat:@"name like %@", @"*7*"]];


NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];

self.orders = [self.managedObjectContext
                 executeFetchRequest:request error:&error];

[sortDescriptor release];
[sortDescriptors release];
[request release];
The Big 3
 NSManagedObjectContext




NSPersistentStoreCoordinator       sqlite




  NSManagedObjectModel         .xcdatamodel
NSManagedObjectContext


• Object space for Managed Objects

• Fetches from Persistent Store

• Exclusive to a single thread

• Commit and Discard Changes
NSManagedObjectContext
                                    (lazy loaded in AppDelegate)

- (NSManagedObjectContext *)managedObjectContext
{
   if (__managedObjectContext != nil)
   {
       return __managedObjectContext;
   }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil)
    {
        __managedObjectContext = [[NSManagedObjectContext alloc] init];
        [__managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    return __managedObjectContext;
}
NSPersistentStoreCoordinator


• Manages connections to stores

• Maps data model to database

• Handles many stores

• Shared between threads
NSPersistentStoreCoordinator
                                  (lazy loaded in AppDelegate)

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
   if (__persistentStoreCoordinator != nil)
   {
       return __persistentStoreCoordinator;
   }

  NSURL *storeURL = [[self applicationDocumentsDirectory]
      URLByAppendingPathComponent:@"MyApp.sqlite"];

  NSError *error = nil;
  __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
                    initWithManagedObjectModel:[self managedObjectModel]];

  if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                 configuration:nil URL:storeURL options:nil error:&error]) { }

   return __persistentStoreCoordinator;
   }
NSManagedObjectModel

• Definition of database schema

• Describes entity objects in store

• Predefined Queries - Fetch Requests

• Relationships between entities
NSManagedObjectModel
                                   (lazy loaded in AppDelegate)



- (NSManagedObjectModel *)managedObjectModel
{
   if (__managedObjectModel != nil)
   {
       return __managedObjectModel;
   }

    NSURL *modelURL = [[NSBundle mainBundle]
          URLForResource:@"MyApp" withExtension:@"momd"];

    __managedObjectModel = [[NSManagedObjectModel alloc]
                    initWithContentsOfURL:modelURL];

    return __managedObjectModel;
}
NSManagedObjectModel
    XCode Editor
Insert new
                   NSManagedObject
NSManagedObject *car = [NSEntityDescription insertNewObjectForEntityForName:@"Car”
            inManagedObjectContext:self.managedObjectContext];

[car setValue:@"Jeep" forKey:@"name"];

//Save the whole context which will save all the objects in it
NSError *error = nil;
if ([self.managedObjectContext save:&error]) {
     NSLog(@"Saved");
} else {
     NSLog(@"Error saving %@", [error localizedDescription]);
}
Threads
                                   Pass ID between threads




               Thread1                                                  Thread2




Object id=1                                                                         Object id=1




  Object                                                                              Object
              NSManagedObjectContext                       NSManagedObjectContext
   id=1                                                                                id=1




                                  NSPersistentStoreCoordinator




                                        SQLite Database




                                          Object id=1
Memory Usage
self.orders = [self.managedObjectContext executeFetchRequest:request error:&error];




         •   Load into an Array

         • All in memory

         • Updates

         • Fast and Easy for small tables
NSFetchedResultsController


• Efficiently backs a UITableView

• Reduces memory usage

• Caches results

• Updates table for changes
NSFetchedResultsController

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController
alloc]
initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext
sectionNameKeyPath:nil cacheName:@"Root"];
The Big Picture
                                                              UITableView
                                            NSManagedObject
NSFetchedResultsController
                                            NSManagedObject   iPhone
                                            NSManagedObject   iPod touch
                                            NSManagedObject
                                                              iPad
                                            NSManagedObject
 NSManagedObjectContext                                       Steve Jobs Rocks




NSPersistentStoreCoordinator       sqlite




  NSManagedObjectModel         .xcdatamodel
Relationships
• to-one
 •   NSManagedObject *manager = [employee valueForKey:@”manager”];




• to-many
 •   NSSet *directReports = [manager valueForKey:@”directReports”];




• Define inverses for data integrity
• Delete Rules - nullify, cascade, deny
Fetched Properties

• Lazy loaded query relationship

• Sorted

• Predicate - filtered

• “Give a list of direct reports that begin with the
  letter C”
Fetch Requests

• Uses NSPredicate for Where clause
• Uses NSSortDescriptor for Order By clause
• Can be saved with Managed Object Model
  [fetchRequestTemplateForName]
Predicates

•   [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", searchText];

•   @"name BETWEEN %@", [NSArray arrayWithObjects:@”a”,@”b”,nil]

•   MATCHES for regex

•   CONTAINS[c] for case insenstivity

•   AND, OR, NOT
Default Project with Core

                                   1. [awakeFromNib]
         AppDelegate                                             RootViewController
                               set managedObjectContext




   2. [managedObjectContext]                                  3. [cellForRowAtIndexPath]
           lazy load                                      lazy load fetchedResultsController




   NSManagedObjectContext                                     fetchedResultsController
SQLite Tables
Z_PRIMARYKEY
Preloaded Database
• Load up database using Base
• Base lets you import csv
• Make sure you set the primary keys
• On start check for existence, then copy it over
Preloading Database
NSString *storePath = [[self applicationDocumentsDirectory]
    stringByAppendingPathComponent: @"products.sqlite"];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
 
// Put down default db if it doesn't already exist
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:storePath]) {
    NSString *defaultStorePath = [[NSBundle mainBundle]
        pathForResource:@"preloaded_products" ofType:@"sqlite"];
    if (defaultStorePath) {
        [fileManager copyItemAtPath:defaultStorePath toPath:storePath
error:NULL];
    }
}
FMDB
• Objective-C wrapper for SQLite

• Direct access

• Low overhead

• Great for simple data needs

• https://github.com/ccgus/fmdb
FMDB Example
FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/my.db"];
[db open]
FMResultSet *rs = [db executeQuery:@"select * from orders where customer_id = ?",
@"1000"];

    [rs intForColumn:@"c"],
    [rs stringForColumn:@"b"],
    [rs dateForColumn:@"d"],
    [rs doubleForColumn:@"e"]);
}
[rs close];
[db close];
Links
•   http://www.raywenderlich.com/934/core-data-
    tutorial-getting-started

• http://menial.co.uk/software/base/
• https://github.com/ccgus/fmdb
Thank You!




 @cmar on twitter
  http://cmar.me

More Related Content

PDF
Core Data with multiple managed object contexts
PDF
Create a Core Data Observer in 10mins
PDF
High Performance Core Data
PPT
Core data orlando i os dev group
PDF
Simpler Core Data with RubyMotion
KEY
Data perisistence in iOS
PDF
Bonjour, iCloud
PDF
Beginning icloud development - Cesare Rocchi - WhyMCA
Core Data with multiple managed object contexts
Create a Core Data Observer in 10mins
High Performance Core Data
Core data orlando i os dev group
Simpler Core Data with RubyMotion
Data perisistence in iOS
Bonjour, iCloud
Beginning icloud development - Cesare Rocchi - WhyMCA

What's hot (20)

PDF
ERGroupware
PDF
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
PDF
iOS for ERREST - alternative version
PDF
Symfony Day 2010 Doctrine MongoDB ODM
PDF
Client Server Communication on iOS
PDF
CDI 2.0 Deep Dive
KEY
Node js mongodriver
PPTX
Google cloud datastore driver for Google Apps Script DB abstraction
PDF
Doctrine MongoDB Object Document Mapper
PDF
REST/JSON/CoreData Example Code - A Tour
PDF
Symfony2 from the Trenches
PPTX
Indexing and Query Optimization
PDF
Database madness with_mongoengine_and_sql_alchemy
PPTX
Dbabstraction
PPTX
Indexing & Query Optimization
PDF
20120121
PDF
Utopia Kindgoms scaling case: From 4 to 50K users
PDF
Http4s, Doobie and Circe: The Functional Web Stack
PDF
Drupal 8: Fields reborn
PPTX
Django - sql alchemy - jquery
ERGroupware
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
iOS for ERREST - alternative version
Symfony Day 2010 Doctrine MongoDB ODM
Client Server Communication on iOS
CDI 2.0 Deep Dive
Node js mongodriver
Google cloud datastore driver for Google Apps Script DB abstraction
Doctrine MongoDB Object Document Mapper
REST/JSON/CoreData Example Code - A Tour
Symfony2 from the Trenches
Indexing and Query Optimization
Database madness with_mongoengine_and_sql_alchemy
Dbabstraction
Indexing & Query Optimization
20120121
Utopia Kindgoms scaling case: From 4 to 50K users
Http4s, Doobie and Circe: The Functional Web Stack
Drupal 8: Fields reborn
Django - sql alchemy - jquery
Ad

Viewers also liked (17)

PDF
Интуит. Разработка приложений для iOS. Лекция 8. Работа с данными
PPTX
MVVMCross da Windows Phone a Windows 8 passando per Android e iOS
PDF
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
KEY
RubyMotion
PDF
iOS: A Broad Overview
PDF
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
PDF
[Srijan Wednesday Webinars] Building Full-Fledged Native Apps Using RubyMotion
PDF
Introduction à l'Agilité
PDF
Rapport de stage de fin d'etude l3 angelito & hasina
PPTX
Conception et réalisation du module agenda partagé pour une solution de télés...
PPTX
Cisco Live Milan 2015 - BGP advance
PPTX
PPTX
Presentation pfe application de pointage ASP.NET
PDF
Seminaire Borland UML (2003)
PPTX
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
PPTX
gestion de magasin vente matériels informatique
Интуит. Разработка приложений для iOS. Лекция 8. Работа с данными
MVVMCross da Windows Phone a Windows 8 passando per Android e iOS
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
RubyMotion
iOS: A Broad Overview
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
[Srijan Wednesday Webinars] Building Full-Fledged Native Apps Using RubyMotion
Introduction à l'Agilité
Rapport de stage de fin d'etude l3 angelito & hasina
Conception et réalisation du module agenda partagé pour une solution de télés...
Cisco Live Milan 2015 - BGP advance
Presentation pfe application de pointage ASP.NET
Seminaire Borland UML (2003)
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
gestion de magasin vente matériels informatique
Ad

Similar to iOSDevCamp 2011 Core Data (20)

ODP
MobileCity:Core Data
PPT
Core Data Migration
PPT
Connecting to a REST API in iOS
PDF
Core Data with Swift 3.0
PPT
Core data optimization
PDF
Intro to Core Data
PDF
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
PPTX
Core Data Performance Guide Line
PDF
CoreData Best Practices (2021)
PPTX
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
PDF
Developing iOS REST Applications
KEY
Data perisistance i_os
PDF
Lean React - Patterns for High Performance [ploneconf2017]
PDF
10 tips for a reusable architecture
KEY
PPTX
Real World MVC
PPTX
iOS Beginners Lesson 4
KEY
Taking a Test Drive
ODP
Slickdemo
PDF
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
MobileCity:Core Data
Core Data Migration
Connecting to a REST API in iOS
Core Data with Swift 3.0
Core data optimization
Intro to Core Data
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
Core Data Performance Guide Line
CoreData Best Practices (2021)
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
Developing iOS REST Applications
Data perisistance i_os
Lean React - Patterns for High Performance [ploneconf2017]
10 tips for a reusable architecture
Real World MVC
iOS Beginners Lesson 4
Taking a Test Drive
Slickdemo
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity

iOSDevCamp 2011 Core Data

  • 1. Pulling back the curtain on Core Data Chris Mar Spree Commerce http://cmar.me
  • 2. Chris Mar • Spree Commerce • iOS and Rails Developer • @cmar • Grassy Knoll Apps - Redskins Radar
  • 3. Goal Pull back the curtain on Core Data so you will use it on your next project without fear! (we’ll focus on concepts, not a tutorial)
  • 4. Core Data • Object Relational Mapping • Gives you access to a database without using sql or parsing results • Cocoa API with XCode tooling to assist you • Hibernate for Java, ActiveRecord for Rails
  • 5. Storage Types • SQLite Database • XML • In-Memory we’ll focus on SQLite
  • 6. NSManagedObject • Row from the database • Key-Value coding for fields • Optionally subclass • Fetched from NSManagedObjectContext [employee valueForKey:@"name"];
  • 7. Managed Objects object1 object2 object1 object2 NSManagedObjectContext NSPersistentStoreCoordinator NSManagedObjectModel object1 SQLite Database
  • 8. FetchRequest for NSManagedObjects NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:[NSEntityDescription entityForName:@"Order" inManagedObjectContext:self.managedObjectContext]]; [request setPredicate:[NSPredicate predicateWithFormat:@"name like %@", @"*7*"]]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; self.orders = [self.managedObjectContext executeFetchRequest:request error:&error]; [sortDescriptor release]; [sortDescriptors release]; [request release];
  • 9. The Big 3 NSManagedObjectContext NSPersistentStoreCoordinator sqlite NSManagedObjectModel .xcdatamodel
  • 10. NSManagedObjectContext • Object space for Managed Objects • Fetches from Persistent Store • Exclusive to a single thread • Commit and Discard Changes
  • 11. NSManagedObjectContext (lazy loaded in AppDelegate) - (NSManagedObjectContext *)managedObjectContext { if (__managedObjectContext != nil) { return __managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { __managedObjectContext = [[NSManagedObjectContext alloc] init]; [__managedObjectContext setPersistentStoreCoordinator:coordinator]; } return __managedObjectContext; }
  • 12. NSPersistentStoreCoordinator • Manages connections to stores • Maps data model to database • Handles many stores • Shared between threads
  • 13. NSPersistentStoreCoordinator (lazy loaded in AppDelegate) - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { return __persistentStoreCoordinator; } NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyApp.sqlite"]; NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { } return __persistentStoreCoordinator; }
  • 14. NSManagedObjectModel • Definition of database schema • Describes entity objects in store • Predefined Queries - Fetch Requests • Relationships between entities
  • 15. NSManagedObjectModel (lazy loaded in AppDelegate) - (NSManagedObjectModel *)managedObjectModel { if (__managedObjectModel != nil) { return __managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyApp" withExtension:@"momd"]; __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return __managedObjectModel; }
  • 16. NSManagedObjectModel XCode Editor
  • 17. Insert new NSManagedObject NSManagedObject *car = [NSEntityDescription insertNewObjectForEntityForName:@"Car” inManagedObjectContext:self.managedObjectContext]; [car setValue:@"Jeep" forKey:@"name"]; //Save the whole context which will save all the objects in it NSError *error = nil; if ([self.managedObjectContext save:&error]) { NSLog(@"Saved"); } else { NSLog(@"Error saving %@", [error localizedDescription]); }
  • 18. Threads Pass ID between threads Thread1 Thread2 Object id=1 Object id=1 Object Object NSManagedObjectContext NSManagedObjectContext id=1 id=1 NSPersistentStoreCoordinator SQLite Database Object id=1
  • 19. Memory Usage self.orders = [self.managedObjectContext executeFetchRequest:request error:&error]; • Load into an Array • All in memory • Updates • Fast and Easy for small tables
  • 20. NSFetchedResultsController • Efficiently backs a UITableView • Reduces memory usage • Caches results • Updates table for changes
  • 21. NSFetchedResultsController NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
  • 22. The Big Picture UITableView NSManagedObject NSFetchedResultsController NSManagedObject iPhone NSManagedObject iPod touch NSManagedObject iPad NSManagedObject NSManagedObjectContext Steve Jobs Rocks NSPersistentStoreCoordinator sqlite NSManagedObjectModel .xcdatamodel
  • 23. Relationships • to-one • NSManagedObject *manager = [employee valueForKey:@”manager”]; • to-many • NSSet *directReports = [manager valueForKey:@”directReports”]; • Define inverses for data integrity • Delete Rules - nullify, cascade, deny
  • 24. Fetched Properties • Lazy loaded query relationship • Sorted • Predicate - filtered • “Give a list of direct reports that begin with the letter C”
  • 25. Fetch Requests • Uses NSPredicate for Where clause • Uses NSSortDescriptor for Order By clause • Can be saved with Managed Object Model [fetchRequestTemplateForName]
  • 26. Predicates • [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", searchText]; • @"name BETWEEN %@", [NSArray arrayWithObjects:@”a”,@”b”,nil] • MATCHES for regex • CONTAINS[c] for case insenstivity • AND, OR, NOT
  • 27. Default Project with Core 1. [awakeFromNib] AppDelegate RootViewController set managedObjectContext 2. [managedObjectContext] 3. [cellForRowAtIndexPath] lazy load lazy load fetchedResultsController NSManagedObjectContext fetchedResultsController
  • 30. Preloaded Database • Load up database using Base • Base lets you import csv • Make sure you set the primary keys • On start check for existence, then copy it over
  • 31. Preloading Database NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"products.sqlite"]; NSURL *storeUrl = [NSURL fileURLWithPath:storePath];   // Put down default db if it doesn't already exist NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:storePath]) { NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"preloaded_products" ofType:@"sqlite"]; if (defaultStorePath) { [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL]; } }
  • 32. FMDB • Objective-C wrapper for SQLite • Direct access • Low overhead • Great for simple data needs • https://github.com/ccgus/fmdb
  • 33. FMDB Example FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/my.db"]; [db open] FMResultSet *rs = [db executeQuery:@"select * from orders where customer_id = ?", @"1000"];     [rs intForColumn:@"c"],     [rs stringForColumn:@"b"],     [rs dateForColumn:@"d"],     [rs doubleForColumn:@"e"]); } [rs close]; [db close];
  • 34. Links • http://www.raywenderlich.com/934/core-data- tutorial-getting-started • http://menial.co.uk/software/base/ • https://github.com/ccgus/fmdb
  • 35. Thank You! @cmar on twitter http://cmar.me

Editor's Notes