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

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

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/