LoginSignup
3
3

More than 5 years have passed since last update.

【Realm】RLMObjectがstandaloneオブジェクトかどうかを判断する方法

Last updated at Posted at 2016-08-08

RealmにはStandalone ObjectというRealmの管理化に置かれていない状態と、そうでない状態がある。
判定する方法は簡単で、RLMObjectrealmプロパティを参照すればよい。

Realm Objective-Cのコードだがこのようにメソッド生やしておけば役に立つ。

extension RLMObject {
    var isStandalone: Bool {
        return self.realm == nil
    }
}

ユースケース
キャッシュ(Realm)から取得されたのか、ネットワーク上からStandalone Objectにマッピングされたのかを判断するのに使える。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3