To run the example project, clone the repo, and run pod install
from the Example directory first.
Xcode 15.0.1 Swift 5.0 iOS & tvOS Minimum Deployment Target 12.0
- Increased Deployment Target from iOS and tvOS to 12.0
- Fix files not added to pod
- Added Cloud Kit Support
- Requires commit to be performed now manually, now you have control of when your content is being commited
- Update Swift 5
- Fix relationship between models did not work
Added
store.rollback()
Fix store coordinator with iOS9 and lower
Reverted the throws block but a default sql file path url is being provided, if you won't provide any
If you won't enter a sql file, it will be provided for you. This is the actual implementation:
.userDomainMask, true).first else {
throw SqlFile.filePathNotFound
}
return URL(fileURLWithPath: path).appendingPathComponent("content.sqlite")
Eventually if it can't be created, it throws an error.
You can now observe when a value has been inserted/added, removed, moved or updated.
All you have to do is to change the line in your Store Protocol from var model: Observable<[Entry]>? { get }
to var entities: ManagedObjectObservable<[Entry]>? { get }
or simply access the stores entitities with the parameter entities
. Of course you can still observe the complete entities with
onValueChanged { allEntities in ... }
Here is an example.
override func viewDidLoad() {
super.viewDidLoad()
//..
store.entries?.onItemAdded { entity, indexPath in
//... entity has been added
}
store.entries?.onItemRemoved { entity, indexPath in
//... entity has been removed
}
store.entries?.onItemUpdated { entity, indexPath in
//... entity has been updated
}
store.entries?.onItemMoved { entity, from, to in
//... entity has been moved
}
}
EMStore is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EMStore'
Define a store and implement it like follows. The "Model" is your xcdatamodeld file name. If this is not the same, your app will enventually crash. So be aware.
protocol EntryStore {
var model: Observable<[Entry]>? { get }
var new: Entry? { get }
func add(model: Entry)
func remove(model: Entry)
}
final class DefaultEntryStore: ManagedObjectStore<Entry>, EntryStore {
init() {
super.init(storage: SqliteStorage<Entry>("Model"),
predicate: nil,
sortDescriptors: [NSSortDescriptor(key: "date", ascending: true)])
}
}
Now setup the store just like follows
let store = DefaultEntryStore()
To access the content of a store is farely easy
let fetchedContent = store.entries?.value
To add a new content to a store is again very easy
guard let entry = store.new else {
return
}
entry.date = NSDate()
store.add(model: entry)
And last but not least, we want to be notified, whenever something has been been added or removed. Therefore we use the observeable value property. Use the closure and get notified whenever something may have changed. We may provide more closures in the future to get notified if one entry has been added.
override func viewDidLoad() {
super.viewDidLoad()
//..
store.entries?.onValueChanged { _ in
//... update the table- or collectionview .. or what ever you want to do with the content
}
}
Looking forward for some feedback :)
Martin Eberl, [email protected]
EMStore is available under the MIT license. See the LICENSE file for more info.