Single inverse relationship in Realm models
<p>I'm developing a simple iOS app to learn Swift and I'm using Realm.
As far as I know, in Realm inverse relationships are achieved with a <code>LinkingObjects</code> property which is a collection containing all objects linked to that one.</p>

<p>Consider this example from the Realm Documentation:</p>

<pre><code>class Person: Object {
    // ... other property declarations
    let dogs = List&lt;Dog&gt;()
}

class Dog: Object {
    dynamic var name = ""
    dynamic var age = 0
    let owners = LinkingObjects(fromType: Person.self, property: "dogs")
}
</code></pre>

<p>In my model, I know that each <code>Dog</code> instance will only have <strong><em>one</em></strong> owner since every dog, when created is added to only one <code>Person</code>'s <code>List</code>.</p>

<p>Now I'd like to have a <code>owner: Person</code> property in the <code>Dog</code> class that references to its only owner to make the code more intuitive and simpler (instead of having to write <code>dog.owners.first</code> every time) while keeping the <strong>lazy-loading</strong> behavior (they are lazily loaded, right?).
I don't know how expensive it is to query the "Linking Objects", but since there will be many "Dogs" around, I think it would be better not to access them on object initialization.</p>

<p>For now these are the solutions I could think of:</p>

<p>1:</p>

<pre><code>class Dog: Object {
    let owner: Person = LinkingObjects(fromType: Person.self, property: "dogs").first!
}
</code></pre>

<p>2a:</p>

<pre><code>class Dog: Object {
    private let owners = LinkingObjects(fromType: Person.self, property: "dogs")
    lazy var owner: Person = {return self.owners.first!}()
}
</code></pre>

<p>2b:</p>

<pre><code>class Dog: Object {
    lazy var owner: Person = {
        return LinkingObjects(fromType: Person.self, property: "dogs").first!
    }()
}
</code></pre>

<p>3:</p>

<pre><code>class Dog: Object {

    private let owners = LinkingObjects(fromType: Person.self, property: "dogs")
    var owner: Person {
        return self.owners.first!
    }

}
</code></pre>

<p>I don't think "solution <strong>1</strong>" is lazy loaded and, as in "solution <strong>2</strong>", the <code>owner</code> won't be "auto-updating", however this shouldn't be a problem since in my case a <code>Dog</code> won't ever change owner.</p>

<p>What would you recommend to have a <strong>single</strong> inverse relationship in Swift?</p>