SlideShare a Scribd company logo
Data Persistence in iOS
            Michał Tuszyński
       iOS/Android developer at appvetica




   @srgtuszy       srgtuszy.github.com
Roadmap
Roadmap
1. NSUserDefaults
Roadmap
1. NSUserDefaults
2. NSCache
Roadmap
1. NSUserDefaults
2. NSCache
3. NSCoding protocol
Roadmap
1. NSUserDefaults
2. NSCache
3. NSCoding protocol
4. CoreData
Roadmap
1. NSUserDefaults
2. NSCache
3. NSCoding protocol
4. CoreData
5. iCloud
What are
NSUserDefaults?
What are
           NSUserDefaults?

Key-value local storage, capable of storing both objects
                and primitive data types
What should not be stored in
     NSUserDefaults?
What should not be stored in
           NSUserDefaults?

1. Sensitive data
What should not be stored in
           NSUserDefaults?

1. Sensitive data
2. Heavy objects
What should not be stored in
           NSUserDefaults?

1. Sensitive data
2. Heavy objects
3. Big amounts of data
Demo
What if I need a mechanism to cache big
           amount of objects?
What if I need a mechanism to cache big
           amount of objects?


           ...use NSCache!
Why NSCache?
Why NSCache?
Similar api to NSMutableDictionary class
Why NSCache?
Similar api to NSMutableDictionary class


    - (void)setObject:(id)obj forKey:(id)key;
    - (void)removeObjectForKey:(id)key;
Why NSCache?

Why not just use NSMutableDictionary then?
Why NSCache?
Why not just use NSMutableDictionary then?
Why NSCache?
Why not just use NSMutableDictionary then?

   - NSCache takes care of memory management
Why NSCache?
Why not just use NSMutableDictionary then?

   - NSCache takes care of memory management
   - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num;
   - (void)setTotalCostLimit:(NSUInteger)lim;
Why NSCache?
Why not just use NSMutableDictionary then?

   - NSCache takes care of memory management
   - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num;
   - (void)setTotalCostLimit:(NSUInteger)lim;




   - Will let you know when it disposes data (NSCacheDelegate)
Why NSCache?
Why not just use NSMutableDictionary then?

   - NSCache takes care of memory management
   - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num;
   - (void)setTotalCostLimit:(NSUInteger)lim;




   - Will let you know when it disposes data (NSCacheDelegate)
   - (void)cache:(NSCache *)cache willEvictObject:(id)obj
Demo
How to store custom objects?
How to store custom objects?
         Using archives!
What are archives?
What are archives?
Archives provide a means to convert objects and values
    into architecture-independent stream of bytes
What are archives?
Archives provide a means to convert objects and values
    into architecture-independent stream of bytes
                      Apple documentation
Data perisistence in iOS
Archives
Archives
Archives




Keyed archives
Archives




Keyed archives
Archives




Keyed archives              Sequential archives
What is the difference?
What is the difference?
What is the difference?

Sequential archives
What is the difference?

  Sequential archives
-Encoded from root object
through all interrelated objects
What is the difference?

  Sequential archives
-Encoded from root object
through all interrelated objects

-Must be decoded in the same
order it was encoded
What is the difference?

  Sequential archives              Keyed archives
-Encoded from root object
through all interrelated objects

-Must be decoded in the same
order it was encoded
What is the difference?

  Sequential archives                  Keyed archives
-Encoded from root object          -Each object is assigned a key
through all interrelated objects

-Must be decoded in the same
order it was encoded
What is the difference?

  Sequential archives                  Keyed archives
-Encoded from root object          -Each object is assigned a key
through all interrelated objects

-Must be decoded in the same
order it was encoded

      NSArchiver
What is the difference?

  Sequential archives                  Keyed archives
-Encoded from root object          -Each object is assigned a key
through all interrelated objects

-Must be decoded in the same
order it was encoded

      NSArchiver                        NSKeyedArchiver
How to create an archive out of a custom object?
How to create an archive out of a custom object?


 1.Implement NSCoding protocol inside the object
How to create an archive out of a custom object?


 1.Implement NSCoding protocol inside the object
            - (id)initWithCoder:(NSCoder *)decoder;

            - (void)encodeWithCoder:(NSCoder *)encoder;
How to create an archive out of a custom object?


 1.Implement NSCoding protocol inside the object
            - (id)initWithCoder:(NSCoder *)decoder;

            - (void)encodeWithCoder:(NSCoder *)encoder;




 2. Use one of the NSCoder subclasses to get your archive
Demo
Data perisistence in iOS
Core Data
CoreData is an efficient framework to manage your object
                       persistence
CoreData is an efficient framework to manage your object
                          persistence

Main features:
CoreData is an efficient framework to manage your object
                           persistence

Main features:
-Change tracking and undo support
CoreData is an efficient framework to manage your object
                           persistence

Main features:
-Change tracking and undo support
-Relationship between entities maintenance
CoreData is an efficient framework to manage your object
                           persistence

Main features:
-Change tracking and undo support
-Relationship between entities maintenance
-Automatic validation of property values
CoreData is an efficient framework to manage your object
                           persistence

Main features:
-Change tracking and undo support
-Relationship between entities maintenance
-Automatic validation of property values
-Low memory overhead (Faulting)
What Core Data is not?
What Core Data is not?

-It is not a relational database
What Core Data is not?

-It is not a relational database
-It’s not a silver bullet for your code
How does it work?
How does it work?

      Storage
How does it work?

      Storage
How does it work?

          Storage




 NSPersistentStoreCoordinator
How does it work?

          Storage




                                The bridge between the storage
 NSPersistentStoreCoordinator         and the application
How does it work?

          Storage




                                The bridge between the storage
 NSPersistentStoreCoordinator         and the application
How does it work?

                                Storage




NSManagedObjectModel




                                                      The bridge between the storage
                       NSPersistentStoreCoordinator         and the application
How does it work?

                                              Storage




     NSManagedObjectModel



A collection of data models which
   are used in the application
                                                                    The bridge between the storage
                                     NSPersistentStoreCoordinator         and the application
How does it work?

                                              Storage




     NSManagedObjectModel



A collection of data models which
   are used in the application
                                                                    The bridge between the storage
                                     NSPersistentStoreCoordinator         and the application
How does it work?

                                              Storage




     NSManagedObjectModel



A collection of data models which
   are used in the application
                                                                    The bridge between the storage
                                     NSPersistentStoreCoordinator         and the application




                                      NSManagedObjectContext
How does it work?

                                              Storage




     NSManagedObjectModel



A collection of data models which
   are used in the application
                                                                    The bridge between the storage
                                     NSPersistentStoreCoordinator         and the application




                                                                     Scratchpad which communicates
                                                                                   with
                                      NSManagedObjectContext         NSPersistentStoreCoordinator to
                                                                               save changes
NSManagedObjectModel
NSManagedObjectModel
NSManagedObjectModel

  Entity
NSManagedObjectModel

  Entity




           Relationship
NSManagedObject
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
Can be created using following ways:
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
Can be created using following ways:
1. Designated initializer
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
Can be created using following ways:
1. Designated initializer
- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:
(NSManagedObjectContext *)context
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
Can be created using following ways:
1. Designated initializer
- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:
(NSManagedObjectContext *)context


2. Static method of NSEntityDescription class
NSManagedObject
- Generic class that implements all basic behavior
required by CoreData model object
- It’s not possible to use regular NSObjects with
Core Data
Can be created using following ways:
1. Designated initializer
- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:
(NSManagedObjectContext *)context


2. Static method of NSEntityDescription class
+ (id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext:
(NSManagedObjectContext *)context
Create NSManagedObjects to represent your data model


                   NSManagedObject
                    NSManagedObject
                     NSManagedObject
NSManagedObjects are held in
           NSManagedObjectContext’s cache

NSManagedObject
 NSManagedObject
  NSManagedObject
NSManagedObjects are held in
           NSManagedObjectContext’s cache

NSManagedObject
 NSManagedObject
  NSManagedObject
NSManagedObjects are held in
           NSManagedObjectContext’s cache

NSManagedObject
 NSManagedObject       NSManagedObjectContext
  NSManagedObject
NSManagedObjects are held in
           NSManagedObjectContext’s cache

NSManagedObject
 NSManagedObject       NSManagedObjectContext
  NSManagedObject
NSManagedObjects are held in
           NSManagedObjectContext’s cache

NSManagedObject
 NSManagedObject       NSManagedObjectContext
  NSManagedObject




                                                Save
Demo
Data perisistence in iOS
iCloud
Why should you use iCloud
         APIs?
Why should you use iCloud
           APIs?
1. There’s no need to configure and maintain servers
Why should you use iCloud
            APIs?
1. There’s no need to configure and maintain servers
2. Syncs across all devices without your effort
Why should you use iCloud
            APIs?
1. There’s no need to configure and maintain servers
2. Syncs across all devices without your effort
3. Autosaving and conflict resolving
Why should you use iCloud
            APIs?
1. There’s no need to configure and maintain servers
2. Syncs across all devices without your effort
3. Autosaving and conflict resolving
4. Easily revert to a previous version
iCloud
iCloud
iCloud




Document storage
iCloud




Document storage
iCloud




Document storage            Key-value storage
Document storage

      Application
       sandbox
Document storage

Application
 sandbox
Document storage

Application   iCloud-monitored
 sandbox          directory
Document storage

Application                   iCloud-monitored
              NSFileManager
 sandbox                          directory
Document storage

Application                   iCloud-monitored
              NSFileManager
 sandbox                          directory
Document storage

              setUbiquitous:YES

Application                       iCloud-monitored
               NSFileManager
 sandbox                              directory
Document storage

              setUbiquitous:YES

Application                       iCloud-monitored
               NSFileManager
 sandbox                              directory
Document storage

              setUbiquitous:YES

Application                       iCloud-monitored
               NSFileManager
 sandbox                              directory

              setUbiquitous:NO
Limitations
Limitations
1. Does not work on simulator
Limitations
1. Does not work on simulator
2. A provisioning profile and entitlements are needed to test
Limitations
1. Does not work on simulator
2. A provisioning profile and entitlements are needed to test
3. All files stored in iCloud must be managed by an object that
implements NSFilePresenter protocol
Limitations
1. Does not work on simulator
2. A provisioning profile and entitlements are needed to test
3. All files stored in iCloud must be managed by an object that
implements NSFilePresenter protocol
UIKit provides UIDocument class which implements
NSFilePresenter protocol
Be responsible!
Be responsible!
1. Don’t store any auto generated files in iCloud.
Be responsible!
1. Don’t store any auto generated files in iCloud.
2. Don’t keep any copies of files tracked by iCloud.
Be responsible!
1. Don’t store any auto generated files in iCloud.
2. Don’t keep any copies of files tracked by iCloud.
3. Be careful with large files. Space is limited.
Be responsible!
1. Don’t store any auto generated files in iCloud.
2. Don’t keep any copies of files tracked by iCloud.
3. Be careful with large files. Space is limited.
4. Key-value storage has a limit of 64kb.
Demo
Where to go from here?
Where to go from here?
Where to go from here?




http://www.raywenderlich.com/934/core-data-tutorial-getting-started
Where to go from here?




http://www.raywenderlich.com/934/core-data-tutorial-getting-started
          https://developer.apple.com/videos/wwdc/2011/
Where to go from here?




http://www.raywenderlich.com/934/core-data-tutorial-getting-started
          https://developer.apple.com/videos/wwdc/2011/
  http://developer.apple.com/library/mac/#documentation/cocoa/
               Conceptual/Archiving/Archiving.html
Thank you!
https://github.com/Tuszy/UserDefaultsSample
https://github.com/Tuszy/NSCacheSample
https://github.com/Tuszy/ArchivesSample
https://github.com/Tuszy/CoreDataSample
https://github.com/Tuszy/iCloudSample

              @srgtuszy
         srgtuszy@gmail.com
          srgtuszy.github.com

More Related Content

PDF
Bonjour, iCloud
PDF
Client Server Communication on iOS
KEY
iOSDevCamp 2011 Core Data
PDF
Multithreading on iOS
PDF
Adventures in Multithreaded Core Data
PDF
Multithreading and Parallelism on iOS [MobOS 2013]
PPT
iOS Multithreading
PPT
Connecting to a REST API in iOS
Bonjour, iCloud
Client Server Communication on iOS
iOSDevCamp 2011 Core Data
Multithreading on iOS
Adventures in Multithreaded Core Data
Multithreading and Parallelism on iOS [MobOS 2013]
iOS Multithreading
Connecting to a REST API in iOS

What's hot (20)

PPTX
Indexing & Query Optimization
PPTX
Java Persistence Frameworks for MongoDB
PDF
Granular Archival and Nearline Storage Using MySQL, S3, and SQS
PPTX
MongoDB + Java + Spring Data
PDF
2001: JNDI Its all in the Context
PPTX
Indexing and Query Optimization
PDF
Java Persistence Frameworks for MongoDB
PDF
SICP_2.5 일반화된 연산시스템
PPTX
Easy data-with-spring-data-jpa
PPT
Spring data presentation
PPTX
ElasticSearch for .NET Developers
PPTX
Simplifying Persistence for Java and MongoDB with Morphia
PDF
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
PDF
Requery overview
PPTX
Using Arbor/ RGraph JS libaries for Data Visualisation
DOC
Advanced Hibernate Notes
PDF
Wed 1630 greene_robert_color
PDF
ERGroupware
PPT
PPTX
memcached Distributed Cache
Indexing & Query Optimization
Java Persistence Frameworks for MongoDB
Granular Archival and Nearline Storage Using MySQL, S3, and SQS
MongoDB + Java + Spring Data
2001: JNDI Its all in the Context
Indexing and Query Optimization
Java Persistence Frameworks for MongoDB
SICP_2.5 일반화된 연산시스템
Easy data-with-spring-data-jpa
Spring data presentation
ElasticSearch for .NET Developers
Simplifying Persistence for Java and MongoDB with Morphia
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Requery overview
Using Arbor/ RGraph JS libaries for Data Visualisation
Advanced Hibernate Notes
Wed 1630 greene_robert_color
ERGroupware
memcached Distributed Cache
Ad

Similar to Data perisistence in iOS (20)

PPT
Core data orlando i os dev group
PDF
iOS: Using persistant storage
PDF
Core data WIPJam workshop @ MWC'14
PDF
Core Data
PDF
CoreData
PDF
Using SQLite
KEY
Sqlpo Presentation
PDF
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
PDF
Core data basic Workshop slides NSSpain 2013
KEY
Core Data
PDF
Intro to Core Data
PDF
Persistence on iOS
PDF
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
PDF
Iphone programming: Core Data Tutorial for iOS
PDF
CoreData - there is an ORM you can like!
PDF
Core Data with multiple managed object contexts
PDF
Core data intermediate Workshop at NSSpain 2013
PPTX
Pune-Cocoa: Core data - I
PDF
Simpler Core Data with RubyMotion
PDF
Core Data with Swift 3.0
Core data orlando i os dev group
iOS: Using persistant storage
Core data WIPJam workshop @ MWC'14
Core Data
CoreData
Using SQLite
Sqlpo Presentation
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
Core data basic Workshop slides NSSpain 2013
Core Data
Intro to Core Data
Persistence on iOS
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
Iphone programming: Core Data Tutorial for iOS
CoreData - there is an ORM you can like!
Core Data with multiple managed object contexts
Core data intermediate Workshop at NSSpain 2013
Pune-Cocoa: Core data - I
Simpler Core Data with RubyMotion
Core Data with Swift 3.0
Ad

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
A Presentation on Artificial Intelligence
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
A Presentation on Artificial Intelligence
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Data perisistence in iOS

  • 1. Data Persistence in iOS Michał Tuszyński iOS/Android developer at appvetica @srgtuszy srgtuszy.github.com
  • 6. Roadmap 1. NSUserDefaults 2. NSCache 3. NSCoding protocol 4. CoreData
  • 7. Roadmap 1. NSUserDefaults 2. NSCache 3. NSCoding protocol 4. CoreData 5. iCloud
  • 9. What are NSUserDefaults? Key-value local storage, capable of storing both objects and primitive data types
  • 10. What should not be stored in NSUserDefaults?
  • 11. What should not be stored in NSUserDefaults? 1. Sensitive data
  • 12. What should not be stored in NSUserDefaults? 1. Sensitive data 2. Heavy objects
  • 13. What should not be stored in NSUserDefaults? 1. Sensitive data 2. Heavy objects 3. Big amounts of data
  • 14. Demo
  • 15. What if I need a mechanism to cache big amount of objects?
  • 16. What if I need a mechanism to cache big amount of objects? ...use NSCache!
  • 18. Why NSCache? Similar api to NSMutableDictionary class
  • 19. Why NSCache? Similar api to NSMutableDictionary class - (void)setObject:(id)obj forKey:(id)key; - (void)removeObjectForKey:(id)key;
  • 20. Why NSCache? Why not just use NSMutableDictionary then?
  • 21. Why NSCache? Why not just use NSMutableDictionary then?
  • 22. Why NSCache? Why not just use NSMutableDictionary then? - NSCache takes care of memory management
  • 23. Why NSCache? Why not just use NSMutableDictionary then? - NSCache takes care of memory management - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num; - (void)setTotalCostLimit:(NSUInteger)lim;
  • 24. Why NSCache? Why not just use NSMutableDictionary then? - NSCache takes care of memory management - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num; - (void)setTotalCostLimit:(NSUInteger)lim; - Will let you know when it disposes data (NSCacheDelegate)
  • 25. Why NSCache? Why not just use NSMutableDictionary then? - NSCache takes care of memory management - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)num; - (void)setTotalCostLimit:(NSUInteger)lim; - Will let you know when it disposes data (NSCacheDelegate) - (void)cache:(NSCache *)cache willEvictObject:(id)obj
  • 26. Demo
  • 27. How to store custom objects?
  • 28. How to store custom objects? Using archives!
  • 30. What are archives? Archives provide a means to convert objects and values into architecture-independent stream of bytes
  • 31. What are archives? Archives provide a means to convert objects and values into architecture-independent stream of bytes Apple documentation
  • 37. Archives Keyed archives Sequential archives
  • 38. What is the difference?
  • 39. What is the difference?
  • 40. What is the difference? Sequential archives
  • 41. What is the difference? Sequential archives -Encoded from root object through all interrelated objects
  • 42. What is the difference? Sequential archives -Encoded from root object through all interrelated objects -Must be decoded in the same order it was encoded
  • 43. What is the difference? Sequential archives Keyed archives -Encoded from root object through all interrelated objects -Must be decoded in the same order it was encoded
  • 44. What is the difference? Sequential archives Keyed archives -Encoded from root object -Each object is assigned a key through all interrelated objects -Must be decoded in the same order it was encoded
  • 45. What is the difference? Sequential archives Keyed archives -Encoded from root object -Each object is assigned a key through all interrelated objects -Must be decoded in the same order it was encoded NSArchiver
  • 46. What is the difference? Sequential archives Keyed archives -Encoded from root object -Each object is assigned a key through all interrelated objects -Must be decoded in the same order it was encoded NSArchiver NSKeyedArchiver
  • 47. How to create an archive out of a custom object?
  • 48. How to create an archive out of a custom object? 1.Implement NSCoding protocol inside the object
  • 49. How to create an archive out of a custom object? 1.Implement NSCoding protocol inside the object - (id)initWithCoder:(NSCoder *)decoder; - (void)encodeWithCoder:(NSCoder *)encoder;
  • 50. How to create an archive out of a custom object? 1.Implement NSCoding protocol inside the object - (id)initWithCoder:(NSCoder *)decoder; - (void)encodeWithCoder:(NSCoder *)encoder; 2. Use one of the NSCoder subclasses to get your archive
  • 51. Demo
  • 54. CoreData is an efficient framework to manage your object persistence
  • 55. CoreData is an efficient framework to manage your object persistence Main features:
  • 56. CoreData is an efficient framework to manage your object persistence Main features: -Change tracking and undo support
  • 57. CoreData is an efficient framework to manage your object persistence Main features: -Change tracking and undo support -Relationship between entities maintenance
  • 58. CoreData is an efficient framework to manage your object persistence Main features: -Change tracking and undo support -Relationship between entities maintenance -Automatic validation of property values
  • 59. CoreData is an efficient framework to manage your object persistence Main features: -Change tracking and undo support -Relationship between entities maintenance -Automatic validation of property values -Low memory overhead (Faulting)
  • 60. What Core Data is not?
  • 61. What Core Data is not? -It is not a relational database
  • 62. What Core Data is not? -It is not a relational database -It’s not a silver bullet for your code
  • 63. How does it work?
  • 64. How does it work? Storage
  • 65. How does it work? Storage
  • 66. How does it work? Storage NSPersistentStoreCoordinator
  • 67. How does it work? Storage The bridge between the storage NSPersistentStoreCoordinator and the application
  • 68. How does it work? Storage The bridge between the storage NSPersistentStoreCoordinator and the application
  • 69. How does it work? Storage NSManagedObjectModel The bridge between the storage NSPersistentStoreCoordinator and the application
  • 70. How does it work? Storage NSManagedObjectModel A collection of data models which are used in the application The bridge between the storage NSPersistentStoreCoordinator and the application
  • 71. How does it work? Storage NSManagedObjectModel A collection of data models which are used in the application The bridge between the storage NSPersistentStoreCoordinator and the application
  • 72. How does it work? Storage NSManagedObjectModel A collection of data models which are used in the application The bridge between the storage NSPersistentStoreCoordinator and the application NSManagedObjectContext
  • 73. How does it work? Storage NSManagedObjectModel A collection of data models which are used in the application The bridge between the storage NSPersistentStoreCoordinator and the application Scratchpad which communicates with NSManagedObjectContext NSPersistentStoreCoordinator to save changes
  • 79. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object
  • 80. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data
  • 81. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data Can be created using following ways:
  • 82. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data Can be created using following ways: 1. Designated initializer
  • 83. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data Can be created using following ways: 1. Designated initializer - (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext: (NSManagedObjectContext *)context
  • 84. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data Can be created using following ways: 1. Designated initializer - (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext: (NSManagedObjectContext *)context 2. Static method of NSEntityDescription class
  • 85. NSManagedObject - Generic class that implements all basic behavior required by CoreData model object - It’s not possible to use regular NSObjects with Core Data Can be created using following ways: 1. Designated initializer - (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext: (NSManagedObjectContext *)context 2. Static method of NSEntityDescription class + (id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext: (NSManagedObjectContext *)context
  • 86. Create NSManagedObjects to represent your data model NSManagedObject NSManagedObject NSManagedObject
  • 87. NSManagedObjects are held in NSManagedObjectContext’s cache NSManagedObject NSManagedObject NSManagedObject
  • 88. NSManagedObjects are held in NSManagedObjectContext’s cache NSManagedObject NSManagedObject NSManagedObject
  • 89. NSManagedObjects are held in NSManagedObjectContext’s cache NSManagedObject NSManagedObject NSManagedObjectContext NSManagedObject
  • 90. NSManagedObjects are held in NSManagedObjectContext’s cache NSManagedObject NSManagedObject NSManagedObjectContext NSManagedObject
  • 91. NSManagedObjects are held in NSManagedObjectContext’s cache NSManagedObject NSManagedObject NSManagedObjectContext NSManagedObject Save
  • 92. Demo
  • 95. Why should you use iCloud APIs?
  • 96. Why should you use iCloud APIs? 1. There’s no need to configure and maintain servers
  • 97. Why should you use iCloud APIs? 1. There’s no need to configure and maintain servers 2. Syncs across all devices without your effort
  • 98. Why should you use iCloud APIs? 1. There’s no need to configure and maintain servers 2. Syncs across all devices without your effort 3. Autosaving and conflict resolving
  • 99. Why should you use iCloud APIs? 1. There’s no need to configure and maintain servers 2. Syncs across all devices without your effort 3. Autosaving and conflict resolving 4. Easily revert to a previous version
  • 100. iCloud
  • 101. iCloud
  • 104. iCloud Document storage Key-value storage
  • 105. Document storage Application sandbox
  • 107. Document storage Application iCloud-monitored sandbox directory
  • 108. Document storage Application iCloud-monitored NSFileManager sandbox directory
  • 109. Document storage Application iCloud-monitored NSFileManager sandbox directory
  • 110. Document storage setUbiquitous:YES Application iCloud-monitored NSFileManager sandbox directory
  • 111. Document storage setUbiquitous:YES Application iCloud-monitored NSFileManager sandbox directory
  • 112. Document storage setUbiquitous:YES Application iCloud-monitored NSFileManager sandbox directory setUbiquitous:NO
  • 114. Limitations 1. Does not work on simulator
  • 115. Limitations 1. Does not work on simulator 2. A provisioning profile and entitlements are needed to test
  • 116. Limitations 1. Does not work on simulator 2. A provisioning profile and entitlements are needed to test 3. All files stored in iCloud must be managed by an object that implements NSFilePresenter protocol
  • 117. Limitations 1. Does not work on simulator 2. A provisioning profile and entitlements are needed to test 3. All files stored in iCloud must be managed by an object that implements NSFilePresenter protocol UIKit provides UIDocument class which implements NSFilePresenter protocol
  • 119. Be responsible! 1. Don’t store any auto generated files in iCloud.
  • 120. Be responsible! 1. Don’t store any auto generated files in iCloud. 2. Don’t keep any copies of files tracked by iCloud.
  • 121. Be responsible! 1. Don’t store any auto generated files in iCloud. 2. Don’t keep any copies of files tracked by iCloud. 3. Be careful with large files. Space is limited.
  • 122. Be responsible! 1. Don’t store any auto generated files in iCloud. 2. Don’t keep any copies of files tracked by iCloud. 3. Be careful with large files. Space is limited. 4. Key-value storage has a limit of 64kb.
  • 123. Demo
  • 124. Where to go from here?
  • 125. Where to go from here?
  • 126. Where to go from here? http://www.raywenderlich.com/934/core-data-tutorial-getting-started
  • 127. Where to go from here? http://www.raywenderlich.com/934/core-data-tutorial-getting-started https://developer.apple.com/videos/wwdc/2011/
  • 128. Where to go from here? http://www.raywenderlich.com/934/core-data-tutorial-getting-started https://developer.apple.com/videos/wwdc/2011/ http://developer.apple.com/library/mac/#documentation/cocoa/ Conceptual/Archiving/Archiving.html

Editor's Notes