matghazaryan/Unrealm
matghazaryan/Unrealm has 531 GitHub stars and 73 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-09 12:53 UTC. Last push 2024-08-31.
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.
What you can do
- Swift Primitives
- Swift Dictionaries
- Nested Classes/Structs
- Swift Optionals (String, Data, Date)
Measured star growth
- in 24h
- 0
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original
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:
- Swift Primitives
- Swift Structs
- Swift Classes
- Swift Enums
- Swift Arrays
- Swift Dictionaries
- Nested Classes/Structs
- Swift Optionals (String, Data, Date)
- Swift Optionals of primitives (Int, Float, Double, Bool)
- Swift Optionals of Realmables
- Swift Optionals of Arrays
- 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
- Conform your Classes/Structs to
Realmableprotocol instead of inheriting fromObject. Conform your Enums toRealmableEnumprotocol. - Register your Classes/Structs and Enums in AppDelegate's
didFinishLaunchingWithOptions.
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 justvarorlet - Getting rid of boilerplate code such as
RealmOptional<Int>. Use justInt? - 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.;
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. To install it, simply add the following line to your Podfile:
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:
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.
Explore related projects
Asabeneh/30-Days-Of-Python
The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,486 starsgrafana/grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
77,790 starsredis/redis
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
77,332 starsapache/superset
Apache Superset is a Data Visualization and Data Exploration Platform
75,455 stars