Heaven
Heaven

Reputation: 536

SwiftRealm how to check if a Realm Object has a primary key or not?

Sometimes we may need to check if the realm object has primary key or not. Like if we want to do func add<S>(_ objects: S, update: UpdatePolicy = .error) where S : Sequence, S.Element : Object. If an object already exists in the Realm with the specified primary key and the update policy is .modified or .all. The .error is for objects without a primary key.

Upvotes: 2

Views: 540

Answers (1)

Heaven
Heaven

Reputation: 536

using object.objectSchema.primaryKeyProperty == nil to check if the object has the primary key or not.

Upvotes: 4

Related Questions