ObjectStorage is a framework that make CRUD works on your model entities, you may choose what storage you want e.g. Sqlite, CoreData, plist...
- CoreData
- Sqlite
- UserDefaults
- Keychains
- File
Best thing to do is have a look at ObjectStorageTests.
- Make your model conform to Model protocol, I suggest you create a base class for that, take a look at MappableModel in ObjectStorageTests folder.
class UserProfile: Model
Most import for CoreData is set up your ModelIdentifier in your model.
public typealias ModelIdentifier = (modelName: String, keys: [String], values: [String?])
modelName is the CoreData model name, keys and values will use for CoreData queries.
- Create StorageProviderService instance
let storageProvider = StorageProviderService(coreDataModelFileName: "Model")
- Then CRUD your model
let profile = UserProfile(firstName: 'Jiantang', lastName: 'Li')
storageProvider.create(profile)
storageProvider.update(profile)
let read = storageProvider.read(profile)
storageProvider.delete(profile)
ObjectStorage's already taken, so I use 'LiObjectStorage' instead.
pod 'LiObjectStorage', '~> 0.1.1'
github "tonyli508/ObjectStorage", "~> 0.1.1"
- Simplify Model Protocol.
- More storage support.
- Add more complex testings.
- Carthage support.