{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/comments/26337957","id":26337957,"diff_hunk":"@@ -7,35 +7,122 @@\n //\n \n #import \"MSManagedObjectObserver.h\"\n+#import \"MSCoreDataStore.h\"\n+#import \"MSClient.h\"\n #import <CoreData/CoreData.h>\n \n @interface MSManagedObjectObserver()\n-@property (nonatomic, weak) MSClient *client;\n+@property (nonatomic, strong) MSClient *client;\n+@property (nonatomic, weak) NSManagedObjectContext *context;\n @end\n \n @implementation MSManagedObjectObserver\n \n-- (id) initWithClient:(MSClient *)client\n-{\n-    return [self initWithClient:client contextsToObserver:nil];\n-}\n-\n-- (id) initWithClient:(MSClient *)client contextsToObserver:(NSArray *)contexts\n+- (instancetype) initWithClient:(MSClient *)client\n {\n     self = [super init];\n     if (self) {\n-        _client = client;\n+\t\t// Copy so we can change the handling of how the sync table operations are handled\n+        _client = [client copy];\n+\t\t\n+\t\tif ([_client.syncContext.dataSource isKindOfClass:[MSCoreDataStore class]])\n+\t\t{\n+\t\t\tMSCoreDataStore *dataStore = _client.syncContext.dataSource;\n+\t\t\t_context = dataStore.context;\n+\t\t\t\n+\t\t\t[[NSNotificationCenter defaultCenter] addObserver:self\n+\t\t\t\t\t\t\t\t\t\t\t\t\t selector:@selector(handleDidSaveNotification:)\n+\t\t\t\t\t\t\t\t\t\t\t\t\t\t name:NSManagedObjectContextDidSaveNotification\n+\t\t\t\t\t\t\t\t\t\t\t\t\t   object:_context];\n+\t\t}\n+\t\t\n+\t\t// Modify the handling of sync table operations for this instance of the data source\n+\t\t_client.syncContext.dataSource.handlesSyncTableOperations = FALSE;\n     }\n     return self;\n }\n \n-- (void) registerAsObserver\n+- (void)dealloc\n+{\n+\tif (self.context != nil)\n+\t{\n+\t\t[[NSNotificationCenter defaultCenter] removeObserver:self\n+\t\t\t\t\t\t\t\t\t\t\t\t\t\tname:NSManagedObjectContextDidSaveNotification\n+\t\t\t\t\t\t\t\t\t\t\t\t\t  object:self.context];\n+\t}\n+}\n+\n+/// Checks the entity has the ms_version attribute to signal it should\n+/// be synchronised to the mobile service\n+- (BOOL)entityHasRemoteStoreAttributes:(NSManagedObject *)managedObject\n {\n-    [[NSNotificationCenter defaultCenter] addObserver:self\n-                                             selector:@selector(handleDidSaveNotification:)\n-                                                 name:NSManagedObjectContextDidSaveNotification\n-                                               object:nil];\n+\treturn (managedObject.entity.attributesByName[StoreVersion] != nil);","path":"sdk/iOS/src/MSManagedObjectObserver.m","position":66,"original_position":66,"commit_id":"447821ed4ad5e6ef5bd8084188400bfc92c3b976","original_commit_id":"f8167ff4976ffa33ad979c28164dfd59f43b5c9d","user":{"login":"phvannor","id":3979343,"avatar_url":"https://avatars.githubusercontent.com/u/3979343?v=3","gravatar_id":"","url":"https://api.github.com/users/phvannor","html_url":"https://github.com/phvannor","followers_url":"https://api.github.com/users/phvannor/followers","following_url":"https://api.github.com/users/phvannor/following{/other_user}","gists_url":"https://api.github.com/users/phvannor/gists{/gist_id}","starred_url":"https://api.github.com/users/phvannor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phvannor/subscriptions","organizations_url":"https://api.github.com/users/phvannor/orgs","repos_url":"https://api.github.com/users/phvannor/repos","events_url":"https://api.github.com/users/phvannor/events{/privacy}","received_events_url":"https://api.github.com/users/phvannor/received_events","type":"User","site_admin":false},"body":"Makes sense. I have a couple designs in flight (like dealing with relationships) that would require re-visiting this anyways later on.  It doesn't seem unreasonable for now to put this restriction on using the observer.","created_at":"2015-03-12T19:53:43Z","updated_at":"2015-03-12T19:53:43Z","html_url":"https://github.com/Azure/azure-mobile-services/pull/635#discussion_r26337957","pull_request_url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/comments/26337957"},"html":{"href":"https://github.com/Azure/azure-mobile-services/pull/635#discussion_r26337957"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635","id":31061309,"html_url":"https://github.com/Azure/azure-mobile-services/pull/635","diff_url":"https://github.com/Azure/azure-mobile-services/pull/635.diff","patch_url":"https://github.com/Azure/azure-mobile-services/pull/635.patch","issue_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/635","number":635,"state":"open","locked":false,"title":"[iOS] NSManagedObjectContext save observer","user":{"login":"damienpontifex","id":1321276,"avatar_url":"https://avatars.githubusercontent.com/u/1321276?v=3","gravatar_id":"","url":"https://api.github.com/users/damienpontifex","html_url":"https://github.com/damienpontifex","followers_url":"https://api.github.com/users/damienpontifex/followers","following_url":"https://api.github.com/users/damienpontifex/following{/other_user}","gists_url":"https://api.github.com/users/damienpontifex/gists{/gist_id}","starred_url":"https://api.github.com/users/damienpontifex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienpontifex/subscriptions","organizations_url":"https://api.github.com/users/damienpontifex/orgs","repos_url":"https://api.github.com/users/damienpontifex/repos","events_url":"https://api.github.com/users/damienpontifex/events{/privacy}","received_events_url":"https://api.github.com/users/damienpontifex/received_events","type":"User","site_admin":false},"body":"Context observer for automatic message creation for entities saved with an NSManagedObjectContext. Also prevents the MSCoreDataStore from trying to re-insert/update/delete the entity and just creates the server message as discussed in issue #568 ","created_at":"2015-03-12T17:54:11Z","updated_at":"2015-03-12T19:53:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c2d0cd49d34cf9633eca37b0bfac6d53e3fd676","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/635/comments","statuses_url":"https://api.github.com/repos/Azure/azure-mobile-services/statuses/447821ed4ad5e6ef5bd8084188400bfc92c3b976","head":{"label":"damienpontifex:multiple-contexts","ref":"multiple-contexts","sha":"447821ed4ad5e6ef5bd8084188400bfc92c3b976","user":{"login":"damienpontifex","id":1321276,"avatar_url":"https://avatars.githubusercontent.com/u/1321276?v=3","gravatar_id":"","url":"https://api.github.com/users/damienpontifex","html_url":"https://github.com/damienpontifex","followers_url":"https://api.github.com/users/damienpontifex/followers","following_url":"https://api.github.com/users/damienpontifex/following{/other_user}","gists_url":"https://api.github.com/users/damienpontifex/gists{/gist_id}","starred_url":"https://api.github.com/users/damienpontifex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienpontifex/subscriptions","organizations_url":"https://api.github.com/users/damienpontifex/orgs","repos_url":"https://api.github.com/users/damienpontifex/repos","events_url":"https://api.github.com/users/damienpontifex/events{/privacy}","received_events_url":"https://api.github.com/users/damienpontifex/received_events","type":"User","site_admin":false},"repo":{"id":20985008,"name":"azure-mobile-services","full_name":"damienpontifex/azure-mobile-services","owner":{"login":"damienpontifex","id":1321276,"avatar_url":"https://avatars.githubusercontent.com/u/1321276?v=3","gravatar_id":"","url":"https://api.github.com/users/damienpontifex","html_url":"https://github.com/damienpontifex","followers_url":"https://api.github.com/users/damienpontifex/followers","following_url":"https://api.github.com/users/damienpontifex/following{/other_user}","gists_url":"https://api.github.com/users/damienpontifex/gists{/gist_id}","starred_url":"https://api.github.com/users/damienpontifex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienpontifex/subscriptions","organizations_url":"https://api.github.com/users/damienpontifex/orgs","repos_url":"https://api.github.com/users/damienpontifex/repos","events_url":"https://api.github.com/users/damienpontifex/events{/privacy}","received_events_url":"https://api.github.com/users/damienpontifex/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/damienpontifex/azure-mobile-services","description":"Client SDKs and Samples for Azure Mobile Services","fork":true,"url":"https://api.github.com/repos/damienpontifex/azure-mobile-services","forks_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/forks","keys_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/keys{/key_id}","collaborators_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/teams","hooks_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/hooks","issue_events_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/issues/events{/number}","events_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/events","assignees_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/assignees{/user}","branches_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/branches{/branch}","tags_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/tags","blobs_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/git/refs{/sha}","trees_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/git/trees{/sha}","statuses_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/statuses/{sha}","languages_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/languages","stargazers_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/stargazers","contributors_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/contributors","subscribers_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/subscribers","subscription_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/subscription","commits_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/commits{/sha}","git_commits_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/git/commits{/sha}","comments_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/comments{/number}","issue_comment_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/issues/comments{/number}","contents_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/contents/{+path}","compare_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/compare/{base}...{head}","merges_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/merges","archive_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/downloads","issues_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/issues{/number}","pulls_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/pulls{/number}","milestones_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/milestones{/number}","notifications_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/labels{/name}","releases_url":"https://api.github.com/repos/damienpontifex/azure-mobile-services/releases{/id}","created_at":"2014-06-19T02:27:37Z","updated_at":"2015-03-10T17:39:06Z","pushed_at":"2015-03-12T19:05:19Z","git_url":"git://github.com/damienpontifex/azure-mobile-services.git","ssh_url":"git@github.com:damienpontifex/azure-mobile-services.git","clone_url":"https://github.com/damienpontifex/azure-mobile-services.git","svn_url":"https://github.com/damienpontifex/azure-mobile-services","homepage":"http://azure.microsoft.com/en-us/develop/mobile/","size":25956,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Azure:multiple-contexts","ref":"multiple-contexts","sha":"77be831dd79df89859471917e2a79ecaf5ceda53","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":5803673,"name":"azure-mobile-services","full_name":"Azure/azure-mobile-services","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-mobile-services","description":"Client SDKs and Samples for Azure Mobile Services","fork":false,"url":"https://api.github.com/repos/Azure/azure-mobile-services","forks_url":"https://api.github.com/repos/Azure/azure-mobile-services/forks","keys_url":"https://api.github.com/repos/Azure/azure-mobile-services/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-mobile-services/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-mobile-services/teams","hooks_url":"https://api.github.com/repos/Azure/azure-mobile-services/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-mobile-services/events","assignees_url":"https://api.github.com/repos/Azure/azure-mobile-services/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-mobile-services/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-mobile-services/tags","blobs_url":"https://api.github.com/repos/Azure/azure-mobile-services/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-mobile-services/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-mobile-services/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-mobile-services/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-mobile-services/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-mobile-services/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-mobile-services/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-mobile-services/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-mobile-services/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-mobile-services/subscription","commits_url":"https://api.github.com/repos/Azure/azure-mobile-services/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-mobile-services/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-mobile-services/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-mobile-services/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-mobile-services/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-mobile-services/merges","archive_url":"https://api.github.com/repos/Azure/azure-mobile-services/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-mobile-services/downloads","issues_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-mobile-services/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-mobile-services/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-mobile-services/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-mobile-services/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-mobile-services/releases{/id}","created_at":"2012-09-14T02:04:52Z","updated_at":"2015-03-12T18:44:01Z","pushed_at":"2015-03-12T00:55:19Z","git_url":"git://github.com/Azure/azure-mobile-services.git","ssh_url":"git@github.com:Azure/azure-mobile-services.git","clone_url":"https://github.com/Azure/azure-mobile-services.git","svn_url":"https://github.com/Azure/azure-mobile-services","homepage":"http://azure.microsoft.com/en-us/develop/mobile/","size":57847,"stargazers_count":342,"watchers_count":342,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":214,"mirror_url":null,"open_issues_count":75,"forks":214,"open_issues":75,"watchers":342,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635"},"html":{"href":"https://github.com/Azure/azure-mobile-services/pull/635"},"issue":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/issues/635"},"comments":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/issues/635/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/pulls/635/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-mobile-services/statuses/447821ed4ad5e6ef5bd8084188400bfc92c3b976"}}}}