Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eugene-software/ezadatabase
Convenient library to work with CoreData with Combine
https://github.com/eugene-software/ezadatabase
combine coredata coredata-swift coredatastack database database-management ios stack swift wrapper
Last synced: about 1 month ago
JSON representation
Convenient library to work with CoreData with Combine
- Host: GitHub
- URL: https://github.com/eugene-software/ezadatabase
- Owner: eugene-software
- License: mit
- Created: 2022-10-19T17:49:00.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T10:30:50.000Z (about 1 month ago)
- Last Synced: 2024-11-11T10:46:47.604Z (about 1 month ago)
- Topics: combine, coredata, coredata-swift, coredatastack, database, database-management, ios, stack, swift, wrapper
- Language: Swift
- Homepage:
- Size: 134 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EZADatabase
[![Version](https://img.shields.io/cocoapods/v/EZADatabase.svg?style=flat)](https://cocoapods.org/pods/EZADatabase)
[![License](https://img.shields.io/cocoapods/l/EZADatabase.svg?style=flat)](https://cocoapods.org/pods/EZADatabase)
[![Platform](https://img.shields.io/cocoapods/p/EZADatabase.svg?style=flat)](https://cocoapods.org/pods/EZADatabase)## Requirements
- iOS 13 and above
## Usage Example
Import dependenices:
```swift
import Combine
import EZADatabase
```In AppDelegate run setup method:
```swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
EZADatabase
.openDatabase()
.sink { completion in
} receiveValue: { _ in
}
.store(in: &cancellables)
return true
}
```Create CoreDataCompatible struct that reflects a CoreData model:
```swift
struct User: Codable, Hashable {
var userId: String
var userName: String
}extension User: CoreDataCompatible {
typealias ManagedType = CoreDataUser
var primaryKey: Any {
return userId
}
var primaryKeyName: String {
return "userId"
}
init(managedObject: CoreDataUser) {
userId = managedObject.userId
userName = managedObject.userName
}
}
```Create NSManagedObject subclass that conforms to CoreDataExportable and reflects a CoreDataCompatible model:
```swift
@objc(CoreDataUser)
class CoreDataUser: NSManagedObject {@NSManaged var userId: String
@NSManaged var userName: String
}extension CoreDataUser : CoreDataExportable {
typealias ExportType = User
func configure(with object: User, in storage: EZADatabase.CoreDataStorageInterface) {
userId = object.userId
userName = object.userName
}
func getObject() -> Device {
User(managedObject: self)
}
}
```- To store an object:
```swift
let user = User(userId: "someId", userName: "John")
EZADatabase.importRemoteList([user])
.sink { completion in
} receiveValue: { _ in
}
.store(in: &cancellables)
```- To receive an object:
```swift
EZADatabase.exportRemoteList(predicate: NSPredicate(key: "userId", value: "someId"))
.sink { completion in
} receiveValue: { user in
print(user)
}
.store(in: &cancellables)
```## Installation
### Cocoapods
EZADatabase is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'EZADatabase'
```### Swift Package Manager
1. Right click in the Project Navigator
2. Select "Add Packages..."
3. Search for ```https://github.com/eugene-software/EZADatabase.git```## Author
Eugene Software
## License
EZADatabase is available under the MIT license. See the LICENSE file for more info.