stores - Wasappli/WAMapping GitHub Wiki

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.

Built-in stores

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.

Creating your own store

  1. Adopt WAStoreProtocol
  2. Implement beginTransaction. If needed, prepare your context for any modification.
  3. Implement newObjectForMapping:. This is typically a new for entityName. For CoreData, this is an database insertion on the context.
  4. Implement deleteObject:. Do I need to explain?
  5. Implement objectsWithAttributes: forMapping:. This is where you fetch the existing objects on your store so that WAMapping can update the attributes if needed.
  6. Implement commitTransaction. WAMapping is done with the mapping, you can save the context.

Switch between stores

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.