{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/26080763","id":26080763,"diff_hunk":"@@ -223,55 +227,68 @@ public final class Realm {\n     from a Realm (i.e. `invalidated`) must be false.\n \n     :param: object Object to be added to this Realm.\n+    :param: update If true will try to update existing objects with the same primary key.\n     */\n-    public func add(object: Object) {\n-        RLMAddObjectToRealm(object, rlmRealm, .allZeros)\n+    public func add(object: Object, update: Bool = false) {\n+        var options : RLMCreationOptions = .allZeros\n+        if update == true {\n+            options = RLMCreationOptions.UpdateOrCreate\n+            if object.objectSchema.primaryKeyProperty == nil {\n+                fatalError(\"'\\(object.objectSchema.className)' does not have a primary key and can not be updated\")\n+            }\n+        }\n+        RLMAddObjectToRealm(object, rlmRealm, options)\n     }\n \n     /**\n-    Adds objects in the given sequence to be persisted it in this Realm.\n+    Adds or updates objects in the given sequence to be persisted it in this Realm.\n \n-    :see: add(object:)\n+    :see: add(object:update:)\n \n     :param: objects A sequence which contains objects to be added to this Realm.\n+    :param: update If true will try to update existing objects with the same primary key.\n     */\n-    public func add<S: SequenceType where S.Generator.Element: Object>(objects: S) {\n+    public func add<S: SequenceType where S.Generator.Element: Object>(objects: S, update: Bool = false) {\n         for obj in objects {\n-            add(obj)\n+            add(obj, update: update)\n         }\n     }\n \n     /**\n-    Adds or updates an object to be persisted it in this Realm. The object provided must have a designated\n-    primary key. If no objects exist in the Realm instance with the same primary key value, the object is\n-    inserted. Otherwise, the existing object is updated with any changed values.\n-\n-    As with `add`, the object cannot already be persisted in a different\n-    Realm. Use `createOrUpdate` to copy values to a different Realm.\n-\n-    :param: object Object to be added or updated.\n-    */\n-    public func addOrUpdate(object: Object) {\n-        if object.objectSchema.primaryKeyProperty == nil {\n-            fatalError(\"'\\(object.objectSchema.className)' does not have a primary key and can not be updated\")\n-        }\n+    Create an `Object` with the given object.\n \n-        RLMAddObjectToRealm(object, rlmRealm, RLMCreationOptions.UpdateOrCreate)\n-    }\n+    Creates or updates an instance of this object and adds it to the `Realm` populating\n+    the object represented by value.\n+    \n+    When 'update' is 'true', the object must have a primary key. If no objects exist in\n+    the Realm instance with the same primary key value, the object is inserted. Otherwise, \n+    the existing object is updated with any changed values.\n \n-    /**\n-    Adds or updates objects in the given array to be persisted it in this Realm.\n+    :param: type    The object type to create.\n+    :param: value   The value used to populate the object. This can be any key/value coding compliant\n+                    object, or a JSON dictionary such as those returned from the methods in `NSJSONSerialization`,\n+                    or an `Array` with one object for each persisted property. An exception will be\n+                    thrown if any required properties are not present and no default is set.\n \n-    :see: addOrUpdate(object:)\n+                    When passing in an `Array`, all properties must be present,\n+                    valid and in the same order as the properties defined in the model.\n+    :param: update  If true will try to update existing objects with the same primary key.\n \n-    :param: objects A sequence of `Object`s to be added to this Realm.\n+    :returns: The created object.\n     */\n-    public func addOrUpdate<S: SequenceType where S.Generator.Element: Object>(objects: S) {\n-        for obj in objects {\n-            addOrUpdate(obj)\n+    public func create<T: Object>(type: T.Type, value: AnyObject = [:], update: Bool = false) -> T {\n+        var options : RLMCreationOptions = .allZeros\n+        if update == true {\n+            options = RLMCreationOptions.UpdateOrCreate\n+            if schema[T.className()]?.primaryKeyProperty == nil {\n+                fatalError(\"'\\(T.className())' does not have a primary key and can not be updated\")","path":"RealmSwift/Realm.swift","position":103,"original_position":103,"commit_id":"1718605bd7293c510e81fc9ecb654a8509332bbc","original_commit_id":"1718605bd7293c510e81fc9ecb654a8509332bbc","user":{"login":"jpsim","id":474794,"avatar_url":"https://avatars.githubusercontent.com/u/474794?v=3","gravatar_id":"","url":"https://api.github.com/users/jpsim","html_url":"https://github.com/jpsim","followers_url":"https://api.github.com/users/jpsim/followers","following_url":"https://api.github.com/users/jpsim/following{/other_user}","gists_url":"https://api.github.com/users/jpsim/gists{/gist_id}","starred_url":"https://api.github.com/users/jpsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpsim/subscriptions","organizations_url":"https://api.github.com/users/jpsim/orgs","repos_url":"https://api.github.com/users/jpsim/repos","events_url":"https://api.github.com/users/jpsim/events{/privacy}","received_events_url":"https://api.github.com/users/jpsim/received_events","type":"User","site_admin":false},"body":"All `fatalError`s should throw an exception instead for testing purposes.","created_at":"2015-03-09T21:56:32Z","updated_at":"2015-03-09T21:56:32Z","html_url":"https://github.com/realm/realm-cocoa/pull/1518#discussion_r26080763","pull_request_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/26080763"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/1518#discussion_r26080763"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518","id":29557766,"html_url":"https://github.com/realm/realm-cocoa/pull/1518","diff_url":"https://github.com/realm/realm-cocoa/pull/1518.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/1518.patch","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1518","number":1518,"state":"open","locked":false,"title":"[WIP] Swift Object apis","user":{"login":"alazier","id":250144,"avatar_url":"https://avatars.githubusercontent.com/u/250144?v=3","gravatar_id":"","url":"https://api.github.com/users/alazier","html_url":"https://github.com/alazier","followers_url":"https://api.github.com/users/alazier/followers","following_url":"https://api.github.com/users/alazier/following{/other_user}","gists_url":"https://api.github.com/users/alazier/gists{/gist_id}","starred_url":"https://api.github.com/users/alazier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alazier/subscriptions","organizations_url":"https://api.github.com/users/alazier/orgs","repos_url":"https://api.github.com/users/alazier/repos","events_url":"https://api.github.com/users/alazier/events{/privacy}","received_events_url":"https://api.github.com/users/alazier/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-18T20:00:37Z","updated_at":"2015-03-09T21:56:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0ff19612c99887f2b68a71097642082721f012c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518/commits","review_comments_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518/comments","review_comment_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1518/comments","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/1718605bd7293c510e81fc9ecb654a8509332bbc","head":{"label":"realm:al-swift-object","ref":"al-swift-object","sha":"1718605bd7293c510e81fc9ecb654a8509332bbc","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","created_at":"2012-04-16T20:06:56Z","updated_at":"2015-03-09T21:32:50Z","pushed_at":"2015-03-09T21:33:22Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"http://realm.io","size":110700,"stargazers_count":3148,"watchers_count":3148,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":110,"forks":233,"open_issues":110,"watchers":3148,"default_branch":"master"}},"base":{"label":"realm:al-swift","ref":"al-swift","sha":"6ae3bda6bcb2758cb63d0725ab4b36b7fd83af99","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","created_at":"2012-04-16T20:06:56Z","updated_at":"2015-03-09T21:32:50Z","pushed_at":"2015-03-09T21:33:22Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"http://realm.io","size":110700,"stargazers_count":3148,"watchers_count":3148,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":110,"forks":233,"open_issues":110,"watchers":3148,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/1518"},"issue":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/1518"},"comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/1518/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/1518/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-cocoa/statuses/1718605bd7293c510e81fc9ecb654a8509332bbc"}}}}