Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we use RLMObject or Object in Swift Realm?

Tags:

swift

realm

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.

like image 497
leech Avatar asked Jun 26 '15 21:06

leech


People also ask

What is @persisted in realm Swift?

@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.

What are .objects realm?

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 .


1 Answers

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 :)

like image 92
Logan Avatar answered Nov 15 '22 07:11

Logan