This document discusses various data persistence options in iOS, including NSUserDefaults, NSCache, archives using the NSCoding protocol, Core Data, and iCloud. It provides an overview and examples of each technique. NSUserDefaults is best for small amounts of non-sensitive data. NSCache is useful for caching objects in memory. Archives allow custom objects to be encoded and stored. Core Data provides a full object graph and relationship management system. iCloud syncs data across devices.
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
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
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
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)
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
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
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
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
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.
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