SlideShare a Scribd company logo
1 of 84
Download to read offline
Tomáš Jukin
@Inza
Core Data
there is an ORM you can like!
Core Data?
Core Data?
-- It’s a big hairy mess!
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard.
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard. Really?
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard. Really? Really.
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard. Really? Really.
CoreData is hairy
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard. Really? Really.
CoreData is hairy
because it ...
Core Data?
-- It’s a big hairy mess!
YES! but Why?
Real problems are hard. Really? Really.
CoreData is hairy
because it ...
... solves real problems!
Tomáš Jukin
@Inza
www.juicymo.cz
@JuicymoCZ
1) WHY and WHEN to
use Core Data?
1) WHY and WHEN to
use Core Data?
2) HOW to use Core
Data?
WHY?
1) Death
1) Death
2) Taxes
1) Death
2) Taxes
3) SW Requirements
WILL change
“Do you understand how to
structure real-world data
access for Mac and iOS
applications better than
Apple?”
“Do you understand how to
structure real-world data
access for Mac and iOS
applications better than
Apple?”
-- Nope.
• Handling future changes to the data
schema
• Bi-directional sync with servers
• Bi-directional sync with peers (e.g. iPad <-> iPhone)
• Undo - Redo
• Multithreading long-running operations
• Sync data between multiple threads
• Notifying faraway code about changes to
objects so that they can refresh or
update at appropriate intervals
Has your own so-called
“data stack” features like this?
Do I need these features?
(= WHEN?)
But if...
I NEVER update my app!
My users NEVER do mistakes!
I NEVER use threads!
My app is just one view!
My data operations ARE all instantaneous!
Requirements of my apps NEVER changes!
1) Death
2) Taxes
3) SW Requirements
WILL change
... all of that is TRUE for you
Core Data is NOT for you.
... all of that is TRUE for you
Core Data is NOT for you.
Otherwise you
SHOULD use it.
Core Data =
Do not implement
Do not test
Do not optimize
Core Data =
Do not implement
Do not test
Do not optimize
Data Stack code used by your app!
Apple has already done
that!
Fact
Apple’s high-level APIs can
be much faster than YOUR
“optimized” code at lower
levels
Fact
Example:
Fast Image? ➜
UIImageView
Fact
CoreData
is
Cocoa
for Models
Cocoa for Models
Is UIButton easy?
Is UITableView easy?
Is Delegation Pattern easy?
Is InterfaceBuilder and
outlets easy?
Cocoa for Models
Is UIButton easy?
Is UITableView easy?
Is Delegation Pattern easy?
Is InterfaceBuilder and
outlets easy?
NOPE!
Cocoa for Models
Are they powerful?
Cocoa for Models
Are they powerful?
YES!
Why NOT to use Core Data?
•Programmer naivity
•Programmer naivity
➜ “My app isn’t complex enought”
= I am too lazy to learn it
Why NOT to use Core Data?
•Programmer naivity
➜ “My app isn’t complex enought”
= I am too lazy to learn it
➜ “I dont like large frameworks - I used them
in HALF of my app and it was so much work!”
= Use entirely it or not. Otherwise it will
not save time & effort
Why NOT to use Core Data?
•Programmer naivity
➜ “My app isn’t complex enought”
= I am too lazy to learn it
➜ “I dont like large frameworks - I used them
in HALF of my app and it was so much work!”
= Use entirely it or not. Otherwise it will
not save time & effort
•Willful ignorance
Why NOT to use Core Data?
•Programmer naivity
➜ “My app isn’t complex enought”
= I am too lazy to learn it
➜ “I dont like large frameworks - I used them
in HALF of my app and it was so much work!”
= Use entirely it or not. Otherwise it will
not save time & effort
•Willful ignorance
➜ “I don’t have any idea what I’m talking
about, but it sounds like a bad idea to me”
= What?
Why NOT to use Core Data?
So?
Reading code is hard
Writing code is easy
Why learn when we can re-invent?
Really? If this works in your world,
Core Data is not for you...
OK, but when seriously NO?
Update HUGE part of DB in one
moment
Working with lots of records
➜ RSS Reader app
Still not ready to use Core Data?
Read this:
goo.gl/Flzrsk
Numbers here:
goo.gl/lNFjdr
HOW?
.sqlite
Schema
App
.sqlite
ORM Schema
App
.sqlite
App
Core Data Schema
App
.sqlite
Web
Store
.sqlite
App
Schema
App
.sqlite
Web
Store
NSManaged
ObjectContext
NSManaged
ObjectContext
NSManaged
ObjectModel
Persistent
ObjectStore
Persistent
ObjectStore
Persistent
ObjectStore
Persistent
Store Coordinator
.sqlite
App
Schema
App
.sqlite
Web
Store
NSManaged
Object
NSManaged
Object
NSManaged
Object
NSManaged
ObjectContext
NSManaged
ObjectContext
NSManaged
ObjectModel
Persistent
ObjectStore
Persistent
ObjectStore
Persistent
ObjectStore
Persistent
Store Coordinator
...Complex ORM
=> Complex Setup
Setup
// In the AppDelegate.h
@property (readonly, strong, nonatomic) NSManagedObjectContext
*managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator
*persistentStoreCoordinator;
 
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
 
// In the AppDelegate.m
- (void)applicationWillTerminate:(UIApplication *)application
{
// Saves changes in the application's managed object context before the application terminates.
[self saveContext];
}
 
- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext
save:&amp;error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
 
#pragma mark - Core Data stack
 
/**
Returns the managed object context for the application.
If the context doesn't already exist, it is created and bound to the persistent store coordinator for the
application.
*/
- (NSManagedObjectContext *)managedObjectContext
{
if (__managedObjectContext != nil)
{
return __managedObjectContext;
}
 
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil)
{
__managedObjectContext = [[NSManagedObjectContext alloc] init];
[__managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return __managedObjectContext;
}
 
/**
Returns the managed object model for the application.
If the model doesn't already exist, it is created from the application's model.
*/
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"blaba"
withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc]
initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
 
/**
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
 
NSURL *storeURL = [[self applicationDocumentsDirectory]
URLByAppendingPathComponent:@"blaba.sqlite"];
 
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeURL options:nil error:&amp;error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
 
return __persistentStoreCoordinator;
}
 
#pragma mark - Application's Documents directory
 
/**
Returns the URL to the application's Documents directory.
*/
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
}
99 rows!
Really ?!
Core Data bites!
The Cure
1) MagicalRecord
github.com/magicalpanda/MagicalRecord
The Cure
1) MagicalRecord
github.com/magicalpanda/MagicalRecord
2) Mogenerator
github.com/rentzsch/mogenerator
The Cure
1) MagicalRecord
github.com/magicalpanda/MagicalRecord
2) Mogenerator
github.com/rentzsch/mogenerator
+ CocoaPods (as usual)
Magical Record
Magical Record
Nice (Rails like) API
on Core Data
Magical Record
Nice (Rails like) API
on Core Data
You still can dive in!
// In the AppDelegate.h
@property (readonly, strong, nonatomic) NSManagedObjectContext
*managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator
*persistentStoreCoordinator;
 
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
 
// In the AppDelegate.m
- (void)applicationWillTerminate:(UIApplication *)application
{
// Saves changes in the application's managed object context before the application terminates.
[self saveContext];
}
 
- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext
save:&amp;error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
 
#pragma mark - Core Data stack
 
/**
Returns the managed object context for the application.
If the context doesn't already exist, it is created and bound to the persistent store coordinator for the
application.
*/
- (NSManagedObjectContext *)managedObjectContext
{
if (__managedObjectContext != nil)
{
return __managedObjectContext;
}
 
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil)
{
__managedObjectContext = [[NSManagedObjectContext alloc] init];
[__managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return __managedObjectContext;
}
 
/**
Returns the managed object model for the application.
If the model doesn't already exist, it is created from the application's model.
*/
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"blaba"
withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc]
initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
 
/**
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
 
NSURL *storeURL = [[self applicationDocumentsDirectory]
URLByAppendingPathComponent:@"blaba.sqlite"];
 
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeURL options:nil error:&amp;error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
 
return __persistentStoreCoordinator;
}
 
#pragma mark - Application's Documents directory
 
/**
Returns the URL to the application's Documents directory.
*/
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
}
CD
99 rows!
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)
launchOptions
{
[MagicalRecord
setupCoreDataStackWithStoreNamed:
@"MyDatabase.sqlite"];
// ...
return YES;
}
 
- (void)applicationWillTerminate:(UIApplication *)
application
{
[MagicalRecord cleanUp];
}
MR
11 rows!
Fetch
NSArray	
  *fetchedObjects;
NSManagedObjectContext	
  *context	
  =	
  [self	
  
managedObjectContext];
NSFetchRequest	
  *fetch	
  =	
  [[NSFetchRequest	
  alloc]	
  init];
NSEntityDescription	
  *entityDescription	
  =	
  
[NSEntityDescription	
  entityForName:@"Person"	
  	
  
inManagedObjectContext:context];
[fetch	
  setEntity:entityDescription];
[fetch	
  setPredicate:[NSPredicate	
  
predicateWithFormat:@"age	
  =	
  %d",	
  25]];
NSError	
  *error	
  =	
  nil;
fetchedObjects	
  =	
  [context	
  
executeFetchRequest:fetch	
  error:&error];
if([fetchedObjects	
  count]	
  ==	
  1)
	
  	
  	
  	
  return	
  [fetchedObjects	
  objectAtIndex:0];
else
	
  	
  	
  	
  return	
  nil;
CD
NSArray	
  *fetchedObjects;
NSManagedObjectContext	
  *context	
  =	
  [self	
  
managedObjectContext];
NSFetchRequest	
  *fetch	
  =	
  [[NSFetchRequest	
  alloc]	
  init];
NSEntityDescription	
  *entityDescription	
  =	
  
[NSEntityDescription	
  entityForName:@"Person"	
  	
  
inManagedObjectContext:context];
[fetch	
  setEntity:entityDescription];
[fetch	
  setPredicate:[NSPredicate	
  
predicateWithFormat:@"age	
  =	
  %d",	
  25]];
NSError	
  *error	
  =	
  nil;
fetchedObjects	
  =	
  [context	
  
executeFetchRequest:fetch	
  error:&error];
if([fetchedObjects	
  count]	
  ==	
  1)
	
  	
  	
  	
  return	
  [fetchedObjects	
  objectAtIndex:0];
else
	
  	
  	
  	
  return	
  nil;
CD
[Person findByAttribute:@"age"
withValue:@25];
MR
// Query to find all the persons store into the database
NSArray *persons = [Person MR_findAll];
 
// Query to find all the persons store into the database order by their
'firstname'
NSArray *personsSorted =
[Person MR_findAllSortedBy:@"firstname"
ascending:YES];
 
// Query to find all the persons store into the database which have 25
years old
NSArray *personsWhoHave22 =
[Person MR_findByAttribute:@"age"
withValue:[NSNumber numberWithInt:25]];
 
// Query to find the first person store into the databe
Person *person = [Person MR_findFirst];
MR
// Query to find all the persons store into the database
NSArray *persons = [Person MR_findAll];
 
// Query to find all the persons store into the database order by their
'firstname'
NSArray *personsSorted =
[Person MR_findAllSortedBy:@"firstname"
ascending:YES];
 
// Query to find all the persons store into the database which have 25
years old
NSArray *personsWhoHave22 =
[Person MR_findByAttribute:@"age"
withValue:[NSNumber numberWithInt:25]];
 
// Query to find the first person store into the databe
Person *person = [Person MR_findFirst];
MR
// Query to find all the persons store into the database
NSArray *persons = [Person findAll];
 
// Query to find all the persons store into the database order by their
'firstname'
NSArray *personsSorted =
[Person findAllSortedBy:@"firstname"
ascending:YES];
 
// Query to find all the persons store into the database which have 25
years old
NSArray *personsWhoHave22 =
[Person findByAttribute:@"age"
withValue:[NSNumber numberWithInt:25]];
 
// Query to find the first person store into the databe
Person *person = [Person findFirst];
MR
Background Op
[MagicalRecord	
  saveWithBlock:^(NSManagedObjectContext	
  
*localContext)	
  {
	
  	
  	
  	
  Post	
  *post	
  =	
  
[Post	
  createInContext:localContext];
	
  	
  	
  	
  //	
  photo	
  processing
	
  	
  	
  	
  //	
  update	
  post	
  from	
  photo	
  processing
}	
  completion:^(BOOL	
  success,	
  NSError	
  *error)	
  {
	
  	
  	
  //	
  This	
  is	
  called	
  when	
  data	
  done,	
  
	
  	
  	
  //	
  and	
  is	
  called	
  on	
  the	
  main	
  thread
}];
MR
Mogenerator
Mogenerator
Because Xcode sucks!
Mogenerator
Because Xcode sucks!
_User for machine
User for human
Mogenerator
Because Xcode sucks!
_User for machine
User for human
+ auto regen!
But the docs sucks too!
It coves the basics, but I DO NEED to DIVE in!
goo.gl/9fNe0z
goo.gl/durEGR
Recap
•You want to use Core Data
•You want to use NSFetchResultsController
•You want to use MagicalRecord
•You want to use Mogenerator
•YOP, setup of that is epic!
•You want to use CocoaPods
•YOP, docs for CoreData and MagicalRecord
sucks
LET the CoreData work for you!
For-Mobile
http://srazy.info/for-mobile
Pondělí, 24. 3. 2014  19:00
Jakub Hladík
Automatic builds for iOS
=> Tomorrow!
=> AfterPUB included!
Tomáš Jukin
@Inza
www.juicymo.cz
@JuicymoCZ
Tomáš Jukin
@Inza
www.juicymo.cz@JuicymoCZ
goo.gl/jGLovj
Photo Credits
All photos used are CC from Flickr
http://www.flickr.com/photos/
60256070@N05/8330184193/

More Related Content

Viewers also liked

Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Hussain Mansoor
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS DevelopmentSasha Goldshtein
 
Core Data in Motion
Core Data in MotionCore Data in Motion
Core Data in MotionLori Olson
 
16 CoreData
16 CoreData16 CoreData
16 CoreDataTom Fan
 
Things you might have missed from CoreData
Things you might have missed from CoreDataThings you might have missed from CoreData
Things you might have missed from CoreDataSergey Pronin
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourCarl Brown
 
iOS Beginners Lesson 3
iOS Beginners Lesson 3iOS Beginners Lesson 3
iOS Beginners Lesson 3Calvin Cheng
 
How & where to start iOS development?
How & where to start iOS development?How & where to start iOS development?
How & where to start iOS development?Kazi Mohammad Ekram
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesManjula Jonnalagadda
 
What Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
What Would Steve Do? 10 Lessons from the World's Most Captivating PresentersWhat Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
What Would Steve Do? 10 Lessons from the World's Most Captivating PresentersHubSpot
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
 

Viewers also liked (17)

Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)
 
Data perisistence in iOS
Data perisistence in iOSData perisistence in iOS
Data perisistence in iOS
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
 
Core Data in Motion
Core Data in MotionCore Data in Motion
Core Data in Motion
 
16 CoreData
16 CoreData16 CoreData
16 CoreData
 
A CoreData Journey
A CoreData JourneyA CoreData Journey
A CoreData Journey
 
Things you might have missed from CoreData
Things you might have missed from CoreDataThings you might have missed from CoreData
Things you might have missed from CoreData
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
iOS Beginners Lesson 3
iOS Beginners Lesson 3iOS Beginners Lesson 3
iOS Beginners Lesson 3
 
How & where to start iOS development?
How & where to start iOS development?How & where to start iOS development?
How & where to start iOS development?
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Intro to iOS Development
Intro to iOS DevelopmentIntro to iOS Development
Intro to iOS Development
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changes
 
What Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
What Would Steve Do? 10 Lessons from the World's Most Captivating PresentersWhat Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
What Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
 
How Google Works
How Google WorksHow Google Works
How Google Works
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to Core Data Mess or Solution

Core data WIPJam workshop @ MWC'14
Core data WIPJam workshop @ MWC'14Core data WIPJam workshop @ MWC'14
Core data WIPJam workshop @ MWC'14Diego Freniche Brito
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDavide Mauri
 
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...Spark Summit
 
What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sqlshawty_ds
 
Everything You Were Taught About Java Is Wrong
Everything You Were Taught About Java Is WrongEverything You Were Taught About Java Is Wrong
Everything You Were Taught About Java Is WrongTim Boudreau
 
Practical DMD Scripting
Practical DMD Scripting Practical DMD Scripting
Practical DMD Scripting Zenoss
 
Paytm labs soyouwanttodatascience
Paytm labs soyouwanttodatasciencePaytm labs soyouwanttodatascience
Paytm labs soyouwanttodatascienceAdam Muise
 
Streams on top of Scala - scalar 2015 Warsaw
Streams on top of Scala - scalar 2015 WarsawStreams on top of Scala - scalar 2015 Warsaw
Streams on top of Scala - scalar 2015 WarsawQuentin Adam
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data Modeler
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data ModelerThe Heart of Data Modeling: The Best Data Modeler is a Lazy Data Modeler
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data ModelerDATAVERSITY
 
Datascience and Azure(v1.0)
Datascience and Azure(v1.0)Datascience and Azure(v1.0)
Datascience and Azure(v1.0)Zenodia Charpy
 
Data Science on Azure
Data Science on Azure Data Science on Azure
Data Science on Azure Zenodia Charpy
 
How to Build Tools for Data Scientists That Don't Suck
How to Build Tools for Data Scientists That Don't SuckHow to Build Tools for Data Scientists That Don't Suck
How to Build Tools for Data Scientists That Don't SuckDiana Tkachenko
 
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConStreams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConQuentin Adam
 
Decoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesDecoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesMichael Fons
 
Core data orlando i os dev group
Core data   orlando i os dev groupCore data   orlando i os dev group
Core data orlando i os dev groupAndrew Kozlik
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application danceNicholas Valbusa
 
LanceShivnathHadoopSummit2015
LanceShivnathHadoopSummit2015LanceShivnathHadoopSummit2015
LanceShivnathHadoopSummit2015Lance Co Ting Keh
 

Similar to Core Data Mess or Solution (20)

Core data WIPJam workshop @ MWC'14
Core data WIPJam workshop @ MWC'14Core data WIPJam workshop @ MWC'14
Core data WIPJam workshop @ MWC'14
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...
Bulletproof Jobs: Patterns for Large-Scale Spark Processing: Spark Summit Eas...
 
What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sql
 
Everything You Were Taught About Java Is Wrong
Everything You Were Taught About Java Is WrongEverything You Were Taught About Java Is Wrong
Everything You Were Taught About Java Is Wrong
 
Practical DMD Scripting
Practical DMD Scripting Practical DMD Scripting
Practical DMD Scripting
 
Paytm labs soyouwanttodatascience
Paytm labs soyouwanttodatasciencePaytm labs soyouwanttodatascience
Paytm labs soyouwanttodatascience
 
Streams on top of Scala - scalar 2015 Warsaw
Streams on top of Scala - scalar 2015 WarsawStreams on top of Scala - scalar 2015 Warsaw
Streams on top of Scala - scalar 2015 Warsaw
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data Modeler
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data ModelerThe Heart of Data Modeling: The Best Data Modeler is a Lazy Data Modeler
The Heart of Data Modeling: The Best Data Modeler is a Lazy Data Modeler
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
 
Datascience and Azure(v1.0)
Datascience and Azure(v1.0)Datascience and Azure(v1.0)
Datascience and Azure(v1.0)
 
Data Science on Azure
Data Science on Azure Data Science on Azure
Data Science on Azure
 
How to Build Tools for Data Scientists That Don't Suck
How to Build Tools for Data Scientists That Don't SuckHow to Build Tools for Data Scientists That Don't Suck
How to Build Tools for Data Scientists That Don't Suck
 
Big data made easy with a Spark
Big data made easy with a SparkBig data made easy with a Spark
Big data made easy with a Spark
 
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConStreams on top of scala - #lambdaCon
Streams on top of scala - #lambdaCon
 
Decoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesDecoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between uses
 
Core data orlando i os dev group
Core data   orlando i os dev groupCore data   orlando i os dev group
Core data orlando i os dev group
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application dance
 
LanceShivnathHadoopSummit2015
LanceShivnathHadoopSummit2015LanceShivnathHadoopSummit2015
LanceShivnathHadoopSummit2015
 

More from Tomáš Jukin

How you can build a robot Dr. Strangelove would approve
How you can build a robot Dr. Strangelove would approveHow you can build a robot Dr. Strangelove would approve
How you can build a robot Dr. Strangelove would approveTomáš Jukin
 
When a robot is smart enough?
When a robot is smart enough?When a robot is smart enough?
When a robot is smart enough?Tomáš Jukin
 
How to build Open Hardware self-navigating car robot
How to build Open Hardware self-navigating car robotHow to build Open Hardware self-navigating car robot
How to build Open Hardware self-navigating car robotTomáš Jukin
 
MQTT is your best friend
MQTT is your best friendMQTT is your best friend
MQTT is your best friendTomáš Jukin
 
Internet of Things & Open HW for Web Developers
Internet of Things & Open HW for Web DevelopersInternet of Things & Open HW for Web Developers
Internet of Things & Open HW for Web DevelopersTomáš Jukin
 
Arduino Neural Networks
Arduino Neural NetworksArduino Neural Networks
Arduino Neural NetworksTomáš Jukin
 
Multi-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOSMulti-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOSTomáš Jukin
 
Few tips for great presentations
Few tips for great presentationsFew tips for great presentations
Few tips for great presentationsTomáš Jukin
 
Bezpečnost platformy iOS
Bezpečnost platformy iOSBezpečnost platformy iOS
Bezpečnost platformy iOSTomáš Jukin
 
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013Tomáš Jukin
 
MVC na iOS - For-Mobile 2/2013
MVC na iOS - For-Mobile 2/2013MVC na iOS - For-Mobile 2/2013
MVC na iOS - For-Mobile 2/2013Tomáš Jukin
 
iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012Tomáš Jukin
 
Make the code work for you with #git
Make the code work for you with #gitMake the code work for you with #git
Make the code work for you with #gitTomáš Jukin
 
Tools beyond ruby on rails
Tools beyond ruby on railsTools beyond ruby on rails
Tools beyond ruby on railsTomáš Jukin
 

More from Tomáš Jukin (14)

How you can build a robot Dr. Strangelove would approve
How you can build a robot Dr. Strangelove would approveHow you can build a robot Dr. Strangelove would approve
How you can build a robot Dr. Strangelove would approve
 
When a robot is smart enough?
When a robot is smart enough?When a robot is smart enough?
When a robot is smart enough?
 
How to build Open Hardware self-navigating car robot
How to build Open Hardware self-navigating car robotHow to build Open Hardware self-navigating car robot
How to build Open Hardware self-navigating car robot
 
MQTT is your best friend
MQTT is your best friendMQTT is your best friend
MQTT is your best friend
 
Internet of Things & Open HW for Web Developers
Internet of Things & Open HW for Web DevelopersInternet of Things & Open HW for Web Developers
Internet of Things & Open HW for Web Developers
 
Arduino Neural Networks
Arduino Neural NetworksArduino Neural Networks
Arduino Neural Networks
 
Multi-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOSMulti-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOS
 
Few tips for great presentations
Few tips for great presentationsFew tips for great presentations
Few tips for great presentations
 
Bezpečnost platformy iOS
Bezpečnost platformy iOSBezpečnost platformy iOS
Bezpečnost platformy iOS
 
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
 
MVC na iOS - For-Mobile 2/2013
MVC na iOS - For-Mobile 2/2013MVC na iOS - For-Mobile 2/2013
MVC na iOS - For-Mobile 2/2013
 
iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012
 
Make the code work for you with #git
Make the code work for you with #gitMake the code work for you with #git
Make the code work for you with #git
 
Tools beyond ruby on rails
Tools beyond ruby on railsTools beyond ruby on rails
Tools beyond ruby on rails
 

Recently uploaded

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Recently uploaded (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Core Data Mess or Solution

  • 1. Tomáš Jukin @Inza Core Data there is an ORM you can like!
  • 2.
  • 4. Core Data? -- It’s a big hairy mess!
  • 5. Core Data? -- It’s a big hairy mess! YES! but Why?
  • 6. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard.
  • 7. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard. Really?
  • 8. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard. Really? Really.
  • 9. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard. Really? Really. CoreData is hairy
  • 10. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard. Really? Really. CoreData is hairy because it ...
  • 11. Core Data? -- It’s a big hairy mess! YES! but Why? Real problems are hard. Really? Really. CoreData is hairy because it ... ... solves real problems!
  • 13. 1) WHY and WHEN to use Core Data?
  • 14. 1) WHY and WHEN to use Core Data? 2) HOW to use Core Data?
  • 15. WHY?
  • 18. 1) Death 2) Taxes 3) SW Requirements WILL change
  • 19. “Do you understand how to structure real-world data access for Mac and iOS applications better than Apple?”
  • 20. “Do you understand how to structure real-world data access for Mac and iOS applications better than Apple?” -- Nope.
  • 21. • Handling future changes to the data schema • Bi-directional sync with servers • Bi-directional sync with peers (e.g. iPad <-> iPhone) • Undo - Redo • Multithreading long-running operations • Sync data between multiple threads • Notifying faraway code about changes to objects so that they can refresh or update at appropriate intervals Has your own so-called “data stack” features like this?
  • 22. Do I need these features? (= WHEN?)
  • 23. But if... I NEVER update my app! My users NEVER do mistakes! I NEVER use threads! My app is just one view! My data operations ARE all instantaneous! Requirements of my apps NEVER changes!
  • 24. 1) Death 2) Taxes 3) SW Requirements WILL change
  • 25. ... all of that is TRUE for you Core Data is NOT for you.
  • 26. ... all of that is TRUE for you Core Data is NOT for you. Otherwise you SHOULD use it.
  • 27. Core Data = Do not implement Do not test Do not optimize
  • 28. Core Data = Do not implement Do not test Do not optimize Data Stack code used by your app! Apple has already done that!
  • 29. Fact Apple’s high-level APIs can be much faster than YOUR “optimized” code at lower levels
  • 32. Cocoa for Models Is UIButton easy? Is UITableView easy? Is Delegation Pattern easy? Is InterfaceBuilder and outlets easy?
  • 33. Cocoa for Models Is UIButton easy? Is UITableView easy? Is Delegation Pattern easy? Is InterfaceBuilder and outlets easy? NOPE!
  • 34. Cocoa for Models Are they powerful?
  • 35. Cocoa for Models Are they powerful? YES!
  • 36. Why NOT to use Core Data? •Programmer naivity
  • 37. •Programmer naivity ➜ “My app isn’t complex enought” = I am too lazy to learn it Why NOT to use Core Data?
  • 38. •Programmer naivity ➜ “My app isn’t complex enought” = I am too lazy to learn it ➜ “I dont like large frameworks - I used them in HALF of my app and it was so much work!” = Use entirely it or not. Otherwise it will not save time & effort Why NOT to use Core Data?
  • 39. •Programmer naivity ➜ “My app isn’t complex enought” = I am too lazy to learn it ➜ “I dont like large frameworks - I used them in HALF of my app and it was so much work!” = Use entirely it or not. Otherwise it will not save time & effort •Willful ignorance Why NOT to use Core Data?
  • 40. •Programmer naivity ➜ “My app isn’t complex enought” = I am too lazy to learn it ➜ “I dont like large frameworks - I used them in HALF of my app and it was so much work!” = Use entirely it or not. Otherwise it will not save time & effort •Willful ignorance ➜ “I don’t have any idea what I’m talking about, but it sounds like a bad idea to me” = What? Why NOT to use Core Data?
  • 41. So? Reading code is hard Writing code is easy Why learn when we can re-invent? Really? If this works in your world, Core Data is not for you...
  • 42. OK, but when seriously NO? Update HUGE part of DB in one moment Working with lots of records ➜ RSS Reader app
  • 43. Still not ready to use Core Data? Read this: goo.gl/Flzrsk Numbers here: goo.gl/lNFjdr
  • 44. HOW?
  • 51. Setup
  • 52. // In the AppDelegate.h @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;   - (void)saveContext; - (NSURL *)applicationDocumentsDirectory;   // In the AppDelegate.m - (void)applicationWillTerminate:(UIApplication *)application { // Saves changes in the application's managed object context before the application terminates. [self saveContext]; }   - (void)saveContext { NSError *error = nil; NSManagedObjectContext *managedObjectContext = self.managedObjectContext; if (managedObjectContext != nil) { if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext save:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } }   #pragma mark - Core Data stack   /** Returns the managed object context for the application. If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application. */ - (NSManagedObjectContext *)managedObjectContext { if (__managedObjectContext != nil) { return __managedObjectContext; }   NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { __managedObjectContext = [[NSManagedObjectContext alloc] init]; [__managedObjectContext setPersistentStoreCoordinator:coordinator]; } return __managedObjectContext; }   /** Returns the managed object model for the application. If the model doesn't already exist, it is created from the application's model. */ - (NSManagedObjectModel *)managedObjectModel { if (__managedObjectModel != nil) { return __managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"blaba" withExtension:@"momd"]; __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return __managedObjectModel; }   /** Returns the persistent store coordinator for the application. If the coordinator doesn't already exist, it is created and the application's store added to it. */ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { return __persistentStoreCoordinator; }   NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"blaba.sqlite"];   NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); }   return __persistentStoreCoordinator; }   #pragma mark - Application's Documents directory   /** Returns the URL to the application's Documents directory. */ - (NSURL *)applicationDocumentsDirectory { return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; }
  • 57. The Cure 1) MagicalRecord github.com/magicalpanda/MagicalRecord 2) Mogenerator github.com/rentzsch/mogenerator
  • 58. The Cure 1) MagicalRecord github.com/magicalpanda/MagicalRecord 2) Mogenerator github.com/rentzsch/mogenerator + CocoaPods (as usual)
  • 60. Magical Record Nice (Rails like) API on Core Data
  • 61. Magical Record Nice (Rails like) API on Core Data You still can dive in!
  • 62. // In the AppDelegate.h @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;   - (void)saveContext; - (NSURL *)applicationDocumentsDirectory;   // In the AppDelegate.m - (void)applicationWillTerminate:(UIApplication *)application { // Saves changes in the application's managed object context before the application terminates. [self saveContext]; }   - (void)saveContext { NSError *error = nil; NSManagedObjectContext *managedObjectContext = self.managedObjectContext; if (managedObjectContext != nil) { if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext save:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } }   #pragma mark - Core Data stack   /** Returns the managed object context for the application. If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application. */ - (NSManagedObjectContext *)managedObjectContext { if (__managedObjectContext != nil) { return __managedObjectContext; }   NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { __managedObjectContext = [[NSManagedObjectContext alloc] init]; [__managedObjectContext setPersistentStoreCoordinator:coordinator]; } return __managedObjectContext; }   /** Returns the managed object model for the application. If the model doesn't already exist, it is created from the application's model. */ - (NSManagedObjectModel *)managedObjectModel { if (__managedObjectModel != nil) { return __managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"blaba" withExtension:@"momd"]; __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return __managedObjectModel; }   /** Returns the persistent store coordinator for the application. If the coordinator doesn't already exist, it is created and the application's store added to it. */ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { return __persistentStoreCoordinator; }   NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"blaba.sqlite"];   NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); }   return __persistentStoreCoordinator; }   #pragma mark - Application's Documents directory   /** Returns the URL to the application's Documents directory. */ - (NSURL *)applicationDocumentsDirectory { return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; } CD
  • 64. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions { [MagicalRecord setupCoreDataStackWithStoreNamed: @"MyDatabase.sqlite"]; // ... return YES; }   - (void)applicationWillTerminate:(UIApplication *) application { [MagicalRecord cleanUp]; } MR
  • 66. Fetch
  • 67. NSArray  *fetchedObjects; NSManagedObjectContext  *context  =  [self   managedObjectContext]; NSFetchRequest  *fetch  =  [[NSFetchRequest  alloc]  init]; NSEntityDescription  *entityDescription  =   [NSEntityDescription  entityForName:@"Person"     inManagedObjectContext:context]; [fetch  setEntity:entityDescription]; [fetch  setPredicate:[NSPredicate   predicateWithFormat:@"age  =  %d",  25]]; NSError  *error  =  nil; fetchedObjects  =  [context   executeFetchRequest:fetch  error:&error]; if([fetchedObjects  count]  ==  1)        return  [fetchedObjects  objectAtIndex:0]; else        return  nil; CD
  • 68. NSArray  *fetchedObjects; NSManagedObjectContext  *context  =  [self   managedObjectContext]; NSFetchRequest  *fetch  =  [[NSFetchRequest  alloc]  init]; NSEntityDescription  *entityDescription  =   [NSEntityDescription  entityForName:@"Person"     inManagedObjectContext:context]; [fetch  setEntity:entityDescription]; [fetch  setPredicate:[NSPredicate   predicateWithFormat:@"age  =  %d",  25]]; NSError  *error  =  nil; fetchedObjects  =  [context   executeFetchRequest:fetch  error:&error]; if([fetchedObjects  count]  ==  1)        return  [fetchedObjects  objectAtIndex:0]; else        return  nil; CD
  • 70. // Query to find all the persons store into the database NSArray *persons = [Person MR_findAll];   // Query to find all the persons store into the database order by their 'firstname' NSArray *personsSorted = [Person MR_findAllSortedBy:@"firstname" ascending:YES];   // Query to find all the persons store into the database which have 25 years old NSArray *personsWhoHave22 = [Person MR_findByAttribute:@"age" withValue:[NSNumber numberWithInt:25]];   // Query to find the first person store into the databe Person *person = [Person MR_findFirst]; MR
  • 71. // Query to find all the persons store into the database NSArray *persons = [Person MR_findAll];   // Query to find all the persons store into the database order by their 'firstname' NSArray *personsSorted = [Person MR_findAllSortedBy:@"firstname" ascending:YES];   // Query to find all the persons store into the database which have 25 years old NSArray *personsWhoHave22 = [Person MR_findByAttribute:@"age" withValue:[NSNumber numberWithInt:25]];   // Query to find the first person store into the databe Person *person = [Person MR_findFirst]; MR
  • 72. // Query to find all the persons store into the database NSArray *persons = [Person findAll];   // Query to find all the persons store into the database order by their 'firstname' NSArray *personsSorted = [Person findAllSortedBy:@"firstname" ascending:YES];   // Query to find all the persons store into the database which have 25 years old NSArray *personsWhoHave22 = [Person findByAttribute:@"age" withValue:[NSNumber numberWithInt:25]];   // Query to find the first person store into the databe Person *person = [Person findFirst]; MR
  • 74. [MagicalRecord  saveWithBlock:^(NSManagedObjectContext   *localContext)  {        Post  *post  =   [Post  createInContext:localContext];        //  photo  processing        //  update  post  from  photo  processing }  completion:^(BOOL  success,  NSError  *error)  {      //  This  is  called  when  data  done,        //  and  is  called  on  the  main  thread }]; MR
  • 77. Mogenerator Because Xcode sucks! _User for machine User for human
  • 78. Mogenerator Because Xcode sucks! _User for machine User for human + auto regen!
  • 79. But the docs sucks too! It coves the basics, but I DO NEED to DIVE in! goo.gl/9fNe0z goo.gl/durEGR
  • 80. Recap •You want to use Core Data •You want to use NSFetchResultsController •You want to use MagicalRecord •You want to use Mogenerator •YOP, setup of that is epic! •You want to use CocoaPods •YOP, docs for CoreData and MagicalRecord sucks LET the CoreData work for you!
  • 81. For-Mobile http://srazy.info/for-mobile Pondělí, 24. 3. 2014  19:00 Jakub Hladík Automatic builds for iOS => Tomorrow! => AfterPUB included!
  • 84. Photo Credits All photos used are CC from Flickr http://www.flickr.com/photos/ 60256070@N05/8330184193/