I've seen examples for Realm where they use
class Person: Object {}
as well as
class Person: RLMObject {}
which one are we supposed to use?
Also, I can't get the init function to work for the former. Any help will be appreciated.
@Persisted is used to declare properties on Object subclasses which should be managed by Realm. Int, Bool, String, ObjectId and Date properties can be indexed by passing indexed: true to the initializer.
Realm objects are regular Swift or Objective-C classes, but they also bring a few additional features like live queries. The Swift SDK memory maps Realm objects directly to native Swift or Objective-C objects, which means there's no need to use a special data access library, such as an ORM .
If you're working in Swift, Realm.Object
(Object
) was designed for the Swift interface. It has better type detection and more natural Swift phrases.
Object
is backed by RLMObject
, so you can use RLMObject
if you want, but its an Objective-C api so some things may be a bit more tedious.
tl;dr
Realm made RealmSwift for a reason! Use Object
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With