SaintTail
SaintTail

Reputation: 6470

Get single object from primary key of realm object

I have realm object which is in objective-c class (our project is mix&match between swift and objective-c)

I know that I can access

[ClassName objectForPrimaryKey:] in objc

but I don't know how can I use this method in swift file?

is this possible?

Thanks.

Upvotes: 1

Views: 1306

Answers (2)

Michal Cichon
Michal Cichon

Reputation: 1409

In case if you are using Realm as an Objective-C library in Swift, then:

let object = ClassName(forPrimaryKey: primaryKey)

Upvotes: 1

Alexander Gaidukov
Alexander Gaidukov

Reputation: 759

In case of Swift you should use the following code:

let realm = try! Realm()
let object = realm.object(ofType: ClassName.self, forPrimaryKey: primaryKey)

Upvotes: 2

Related Questions