NSUnknownKeyException when adding object with update true
<p>So I have modeled an object as such </p>

<pre><code>class Post: Object {
    let postId = RealmOptional&lt;Int&gt;()
    dynamic var postImage : PostImage?
    dynamic var postUser: User?

    override class func primaryKey() -&gt; String? {
        return "postId"
    }
 }
</code></pre>

<p>and I am trying to persist it like this: </p>

<pre><code>let realm = try! Realm()
realm.beginWrite()
let post = Post()
post.postId.value = json["image"]["image_id"].intValue
realm.add(post, update: true)
try! realm.commitWrite()
</code></pre>

<p>However when the object is a new one and has not been stored yet I get:</p>

<blockquote>
  <p>** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key (null).'</p>
</blockquote>

<p>There has to be something I am doing wrong because the documentation states that Realms</p>

<pre><code>public func add(object: Object, update: Bool = false)
</code></pre>

<p>will create the object if one with the primary key is not present.</p>

<p>Any help or pointers appreciated!</p>