Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealmSwift.Object with numeric optional primary keys can't be added with update=true #3671

Closed
mrackwitz opened this issue May 30, 2016 · 0 comments · Fixed by #3672
Closed
Assignees
Labels

Comments

@mrackwitz
Copy link
Contributor

Goals

Add an object of a class defined from Swift with a numeric optional primary key to a Realm.

Expected Results

Successfully creating the object.

Actual Results

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

Code Sample

class Post: Object {
    let postId = RealmOptional<Int>()
    dynamic var postImage : PostImage?
    dynamic var postUser: User?

    override class func primaryKey() -> String? {
        return "postId"
    }
 }

class PostTest : XCTestCase {
   func testExample() {
        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()
   }
}
@mrackwitz mrackwitz self-assigned this May 30, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant