-
Notifications
You must be signed in to change notification settings - Fork 1
stores
WAMapping is designed for flexibility with stores. The goal is to avoid you having to use CoreData along this library. If you want to implement a store for SQlite for example, then go for it. Feel free to open any PR with your implementation, I'd be happy to add them to the library.
WAMapping comes with two stores implementation
- WAMemoryStore
A simple store which stores the data inside an NSMutableSet
. No savings on file, juste memory persistent.
- WACoreDataStore
A store to keep persistency on a CoreData stack. The input is an instance of a NSManagedObjectContext
.
- WANSCodingStore
A store to keep persistency using NSCoding. The input is an archive path, usually on your library folder.
- Adopt
WAStoreProtocol
- Implement
beginTransaction
. If needed, prepare your context for any modification. - Implement
newObjectForMapping:
. This is typically anew
forentityName
. For CoreData, this is an database insertion on the context. - Implement
deleteObject:
. Do I need to explain? - Implement
objectsWithAttributes: forMapping:
. This is where you fetch the existing objects on your store so that WAMapping can update the attributes if needed. - Implement
commitTransaction
. WAMapping is done with the mapping, you can save the context.
You noticed that the mapper needs initialization from a store.
This means that you can easily map some objects from a server into CoreData and some others only in memory.
For example: you could fetch a temporary dataset to present to the user. This set would not require any persistency, so create a second mapper with a memory store.