Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matghazaryan/Unrealm
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.
https://github.com/matghazaryan/Unrealm
database db enum ios realm realmswift struct swift xcode
Last synced: 4 days ago
JSON representation
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.
- Host: GitHub
- URL: https://github.com/matghazaryan/Unrealm
- Owner: matghazaryan
- License: mit
- Created: 2019-06-01T19:43:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-31T18:48:09.000Z (3 months ago)
- Last Synced: 2024-11-21T06:37:28.672Z (22 days ago)
- Topics: database, db, enum, ios, realm, realmswift, struct, swift, xcode
- Language: Swift
- Size: 37.9 MB
- Stars: 538
- Watchers: 13
- Forks: 74
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Database / Getting Started)
- awesome-swift - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Libs / Data Management)
- awesome-swift - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Libs / Data Management)
- awesome-macos-libraries - Unrealm - Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm. Language: Swift. (Database)
- fucking-awesome-swift - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Libs / Data Management)
- awesome-ios-star - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Database / Getting Started)
- fucking-awesome-ios - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Database / Getting Started)
- fucking-awesome-ios - Unrealm - Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm. (Database / Getting Started)
- awesome-swift - Unrealm - Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm. ` π 2 months ago` (Data Management [π](#readme))
README
Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm .
Stop inheriting from Object! Go for Protocol-Oriented programming!
Made with β€οΈ by matghazaryan
## Features
Unrealm supports the following types:- [x] Swift Primitives
- [x] Swift Structs
- [x] Swift Classes
- [x] Swift Enums
- [x] Swift Arrays
- [x] Swift Dictionaries
- [x] Nested Classes/Structs
- [x] Swift Optionals (String, Data, Date)
- [x] Swift Optionals of primitives (Int, Float, Double, Bool)
- [x] Swift Optionals of Realmables
- [x] Swift Optionals of Arrays
- [x] Swift Arrays of enums## Example Project
To run the example project, clone the repo, and run `pod install` from the Example directory first.
See also Unit Tests.## Usage
All you have to do is
1. Conform your Classes/Structs to `Realmable` protocol instead of inheriting from `Object`. Conform your Enums to `RealmableEnum` protocol.
2. Register your Classes/Structs and Enums in AppDelegate's `didFinishLaunchingWithOptions`.
```Swift
Realm.registerRealmables(ToDoItem.self)
```
That's it! Now you can store your Struct or Class object into Realm as usually you do with Objc Classes.## Pros and Cons
#### Pros π
- Enables you to store Swift native types (Structs, Classes, Enums, Arrays, Dictionaries, etc...)
- Getting rid of redundant inheriting from Object class
- Getting rid of Realm crashes like "Object has been deleted or invalidated"
- Getting rid of Realm crashes like "Realm accessed from incorrect thread"
- Getting rid of boilerplate code such as `@objc dynamic var`. Use just `var` or `let`
- Getting rid of boilerplate code such as `RealmOptional`. Use just `Int?`
- Works perfect with Swift's Codable and optional types!#### Cons π
- Losing "Live Objects" feature. Which means when you modify an object got from Realm the other ones will not be updated automatically. So after modifying an object you should manually update it in realm.
f.e.;
```Swift
let realm = try! Realm()
var todoItem = realm.object(ofType: ToDoItem.self, forPrimaryKey: "1")
todoItem.text = "Modified text"
try! realm.write {
realm.add(todoItem, update: true) //<- force Realm to update the object
}
```## Installation
### CocoaPods
Unrealm is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'Unrealm'
```### Swift Package Manager
You can also use Swift Package Manager to add Unrealm as a dependency to your project. In order to do so, use the following URL:```bash
https://github.com/matghazaryan/Unrealm.git
```
You need to use "master" branch instead of SPM.
## ToDos- Add more UnitTests
- Create a sample project for Swift Package Manager when dependencies can be added to many targets in a simple project.## Contribution
βοΈ If you like what you see, star us on GitHub.
Find a bug, a typo, or something thatβs not documented well? Weβd love for you to open an issue telling me what I can improve!
Contributions are welcome, and they are greatly appreciated!
## Author
matghazaryan, [email protected]
## License
Unrealm is available under the MIT license. See the LICENSE file for more info.