{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/37665281","id":37665281,"diff_hunk":"@@ -71,66 +91,92 @@ + (void)initialize {\n     }\n     initialized = true;\n \n-    NSMutableArray *schemaArray = [NSMutableArray array];\n-    RLMSchema *schema = [[RLMSchema alloc] init];\n+    s_localNameToClass = [NSMutableDictionary dictionary];\n+    s_partialSharedSchema = [[RLMSchema alloc] init];\n+}\n \n-    unsigned int numClasses;\n-    Class *classes = objc_copyClassList(&numClasses);\n++ (instancetype)partialSharedSchema {\n+    return s_partialSharedSchema;\n+}\n \n-    // first create class to name mapping so we can do array validation\n-    // when creating object schema\n-    s_localNameToClass = [NSMutableDictionary dictionary];\n-    for (unsigned int i = 0; i < numClasses; i++) {\n-        Class cls = classes[i];\n-        static Class objectBaseClass = [RLMObjectBase class];\n-        if (!RLMIsKindOfClass(cls, objectBaseClass) || ![cls shouldPersistToRealm]) {\n-            continue;\n++ (void)registerClasses:(Class *)classes count:(NSUInteger)count {\n+    @synchronized(s_localNameToClass) {\n+        // first create class to name mapping so we can do array validation\n+        // when creating object schema\n+        for (NSUInteger i = 0; i < count; i++) {\n+            Class cls = classes[i];\n+\n+            if (!RLMIsObjectSubclass(cls)) {\n+                continue;\n+            }\n+\n+            NSString *className = NSStringFromClass(cls);\n+            if ([RLMSwiftSupport isSwiftClassName:className]) {\n+                className = [RLMSwiftSupport demangleClassName:className];\n+            }\n+            // NSStringFromClass demangles the names for top-level Swift classes\n+            // but not for nested classes. _T indicates it's a Swift symbol, t\n+            // indicates it's a type, and C indicates it's a class.\n+            else if ([className hasPrefix:@\"_TtC\"]) {\n+                NSString *message = [NSString stringWithFormat:@\"RLMObject subclasses cannot be nested within other declarations. Please move %@ to global scope.\", className];\n+                @throw RLMException(message);\n+            }\n+\n+            if (Class existingClass = s_localNameToClass[className]) {\n+                if (existingClass != cls) {\n+                    NSString *message = [NSString stringWithFormat:@\"RLMObject subclasses with the same name cannot be included twice in the same target. Please make sure '%@' is only linked once to your current target.\", className];\n+                    @throw RLMException(message);\n+                }\n+                continue;\n+            }\n+\n+            s_localNameToClass[className] = cls;\n+\n+            RLMReplaceClassNameMethod(cls, className);\n+            // override sharedSchema classs method to return nil to avoid topo-sort issues\n+            RLMReplaceSharedSchemaMethod(cls, nil);","path":"Realm/RLMSchema.mm","position":97,"original_position":97,"commit_id":"577382a80f2a4ef54213599a55534e962507b253","original_commit_id":"3f1b5cd2f73b8d2fcf9b8948ba99d05b0077846d","user":{"login":"segiddins","id":1946610,"avatar_url":"https://avatars.githubusercontent.com/u/1946610?v=3","gravatar_id":"","url":"https://api.github.com/users/segiddins","html_url":"https://github.com/segiddins","followers_url":"https://api.github.com/users/segiddins/followers","following_url":"https://api.github.com/users/segiddins/following{/other_user}","gists_url":"https://api.github.com/users/segiddins/gists{/gist_id}","starred_url":"https://api.github.com/users/segiddins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/segiddins/subscriptions","organizations_url":"https://api.github.com/users/segiddins/orgs","repos_url":"https://api.github.com/users/segiddins/repos","events_url":"https://api.github.com/users/segiddins/events{/privacy}","received_events_url":"https://api.github.com/users/segiddins/received_events","type":"User","site_admin":false},"body":"No, because calling sharedSchema will cause us to hit this lock if the shared schema isn't loaded yet","created_at":"2015-08-21T18:46:03Z","updated_at":"2015-08-21T18:46:03Z","html_url":"https://github.com/realm/realm-cocoa/pull/2401#discussion_r37665281","pull_request_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/37665281"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/2401#discussion_r37665281"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401","id":42508499,"html_url":"https://github.com/realm/realm-cocoa/pull/2401","diff_url":"https://github.com/realm/realm-cocoa/pull/2401.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/2401.patch","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2401","number":2401,"state":"open","locked":false,"title":"[RLMConfiguration] Allow specifying a set of classes","user":{"login":"segiddins","id":1946610,"avatar_url":"https://avatars.githubusercontent.com/u/1946610?v=3","gravatar_id":"","url":"https://api.github.com/users/segiddins","html_url":"https://github.com/segiddins","followers_url":"https://api.github.com/users/segiddins/followers","following_url":"https://api.github.com/users/segiddins/following{/other_user}","gists_url":"https://api.github.com/users/segiddins/gists{/gist_id}","starred_url":"https://api.github.com/users/segiddins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/segiddins/subscriptions","organizations_url":"https://api.github.com/users/segiddins/orgs","repos_url":"https://api.github.com/users/segiddins/repos","events_url":"https://api.github.com/users/segiddins/events{/privacy}","received_events_url":"https://api.github.com/users/segiddins/received_events","type":"User","site_admin":false},"body":"Closes https://github.com/realm/realm-cocoa/issues/2021.\r\nCloses https://github.com/realm/realm-cocoa/issues/2325.\r\n\r\n\\c @jpsim @bdash @tgoyne ","created_at":"2015-08-14T23:57:04Z","updated_at":"2015-08-21T18:46:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75027ea38419d901d18b7cb468d8f4362da56350","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401/commits","review_comments_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401/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/2401/comments","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/577382a80f2a4ef54213599a55534e962507b253","head":{"label":"realm:seg-configuration-classes","ref":"seg-configuration-classes","sha":"577382a80f2a4ef54213599a55534e962507b253","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-08-21T14:29:34Z","pushed_at":"2015-08-21T01:16:47Z","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":"https://realm.io","size":116497,"stargazers_count":4583,"watchers_count":4583,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":397,"mirror_url":null,"open_issues_count":133,"forks":397,"open_issues":133,"watchers":4583,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"16de7a70830d9f7dff969186334f335761ad2d58","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-08-21T14:29:34Z","pushed_at":"2015-08-21T01:16:47Z","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":"https://realm.io","size":116497,"stargazers_count":4583,"watchers_count":4583,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":397,"mirror_url":null,"open_issues_count":133,"forks":397,"open_issues":133,"watchers":4583,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/2401"},"issue":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/2401"},"comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/2401/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2401/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/2401/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-cocoa/statuses/577382a80f2a4ef54213599a55534e962507b253"}}}}