{"action":"created","comment":{"url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/comments/109691197","pull_request_review_id":30809595,"id":109691197,"diff_hunk":"@@ -0,0 +1,118 @@\n+//\n+//  CoreDataStack.swift\n+//  SwiftSeedProject\n+//\n+//  Created by Lucas Pelizza on 3/30/17.\n+//  Copyright © 2017 Making Sense. All rights reserved.\n+//\n+\n+import CoreData\n+import Foundation\n+\n+class CoreDataStack {\n+    \n+    typealias CoreDataStackCompletion = () -> ()\n+    \n+    private let modelName: String\n+    private let completion: CoreDataStackCompletion\n+    \n+    private var persistentStoreURL: NSURL {\n+        let storeName = \"\\(modelName).sqlite\"\n+        let fileManager = FileManager.default\n+        let documentsDirectoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]\n+        return documentsDirectoryURL.appendingPathComponent(storeName) as NSURL\n+    }\n+    \n+    private lazy var managedObjectModel: NSManagedObjectModel? = {\n+        // The mom and momd files are compiled versions of xcdatamodel and xcdatamodeld files.\n+        guard let modelURL = Bundle.main.url(forResource: self.modelName, withExtension: \"momd\") else {\n+            return nil\n+        }\n+        return NSManagedObjectModel(contentsOf: modelURL)\n+    }()\n+    \n+    private lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {\n+        guard let managedObjectModel = self.managedObjectModel else {\n+            return nil\n+        }\n+        return NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel)\n+    }()\n+    \n+    private lazy var privateManagedObjectContext: NSManagedObjectContext = {\n+        let managedObjectContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)\n+        managedObjectContext.persistentStoreCoordinator = self.persistentStoreCoordinator\n+        return managedObjectContext\n+    }()\n+    \n+    public private(set) lazy var mainManagedObjectContext: NSManagedObjectContext = {\n+        let managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)\n+        managedObjectContext.parent = self.privateManagedObjectContext\n+        return managedObjectContext\n+    }()\n+    \n+    init(modelName: String, completion: @escaping CoreDataStackCompletion) {\n+        self.modelName = modelName\n+        self.completion = completion\n+        setupCoreDataStack()\n+    }\n+    \n+    private func setupCoreDataStack() {\n+        let _ = mainManagedObjectContext.persistentStoreCoordinator\n+        \n+        DispatchQueue.global().async {\n+            self.addPersistentStore()\n+            DispatchQueue.main.async { self.completion() }\n+        }\n+    }\n+    \n+    private func addPersistentStore() {\n+        guard let persistentStoreCoordinator = persistentStoreCoordinator else { fatalError(\"Unable to Initialize Persistent Store Coordinator\") }\n+        \n+        let persistentStoreURL = self.persistentStoreURL\n+        do {\n+            let options = [ NSMigratePersistentStoresAutomaticallyOption : true, NSInferMappingModelAutomaticallyOption : true ]\n+            try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: persistentStoreURL as URL, options: options)\n+            \n+        } catch {\n+            let addPersistentStoreError = error as NSError\n+            \n+            print(\"Unable to Add Persistent Store\")\n+            print(\"\\(addPersistentStoreError.localizedDescription)\")\n+        }\n+    }\n+    \n+    // MARK: - Helper Methods\n+    \n+    public func saveChanges() {\n+        mainManagedObjectContext.performAndWait({","path":"IOS/SwiftSeedProject/SwiftSeedProject/Infrastructure/CoreDataStack/CoreDataStack.swift","position":87,"original_position":87,"commit_id":"1593e25ae22ec82d677136efb8d9dcc8f23700de","original_commit_id":"1593e25ae22ec82d677136efb8d9dcc8f23700de","user":{"login":"lpelizzaMS","id":20521804,"avatar_url":"https://avatars3.githubusercontent.com/u/20521804?v=3","gravatar_id":"","url":"https://api.github.com/users/lpelizzaMS","html_url":"https://github.com/lpelizzaMS","followers_url":"https://api.github.com/users/lpelizzaMS/followers","following_url":"https://api.github.com/users/lpelizzaMS/following{/other_user}","gists_url":"https://api.github.com/users/lpelizzaMS/gists{/gist_id}","starred_url":"https://api.github.com/users/lpelizzaMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpelizzaMS/subscriptions","organizations_url":"https://api.github.com/users/lpelizzaMS/orgs","repos_url":"https://api.github.com/users/lpelizzaMS/repos","events_url":"https://api.github.com/users/lpelizzaMS/events{/privacy}","received_events_url":"https://api.github.com/users/lpelizzaMS/received_events","type":"User","site_admin":false},"body":"I will search about DRY principle.","created_at":"2017-04-04T15:12:53Z","updated_at":"2017-04-04T15:14:37Z","html_url":"https://github.com/makingsensetraining/mobile-pocs/pull/14#discussion_r109691197","pull_request_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/comments/109691197"},"html":{"href":"https://github.com/makingsensetraining/mobile-pocs/pull/14#discussion_r109691197"},"pull_request":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14","id":113546506,"html_url":"https://github.com/makingsensetraining/mobile-pocs/pull/14","diff_url":"https://github.com/makingsensetraining/mobile-pocs/pull/14.diff","patch_url":"https://github.com/makingsensetraining/mobile-pocs/pull/14.patch","issue_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/14","number":14,"state":"open","locked":false,"title":"[MLP-150] - Implement core data stack","user":{"login":"lpelizzaMS","id":20521804,"avatar_url":"https://avatars3.githubusercontent.com/u/20521804?v=3","gravatar_id":"","url":"https://api.github.com/users/lpelizzaMS","html_url":"https://github.com/lpelizzaMS","followers_url":"https://api.github.com/users/lpelizzaMS/followers","following_url":"https://api.github.com/users/lpelizzaMS/following{/other_user}","gists_url":"https://api.github.com/users/lpelizzaMS/gists{/gist_id}","starred_url":"https://api.github.com/users/lpelizzaMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpelizzaMS/subscriptions","organizations_url":"https://api.github.com/users/lpelizzaMS/orgs","repos_url":"https://api.github.com/users/lpelizzaMS/repos","events_url":"https://api.github.com/users/lpelizzaMS/events{/privacy}","received_events_url":"https://api.github.com/users/lpelizzaMS/received_events","type":"User","site_admin":false},"body":"# Background\r\n\r\nWe need to implement the logic to persist data on Swift. Our first approach is Core Data.\r\n\r\n# Changes done\r\nCreate the core data stack. \r\nCreate a  data model\r\nAdded some lines of code on AppDelegate to test the stack\r\n\r\n# Approvers required\r\n@jsmuguruza | @mvazquez-ms | @mmaldini33 | @bsztamfater-ms ","created_at":"2017-03-30T23:31:57Z","updated_at":"2017-04-04T15:14:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a09222faecc6346c6d42c9c0efb25e0bc263afcc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14/commits","review_comments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14/comments","review_comment_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/14/comments","statuses_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/statuses/1593e25ae22ec82d677136efb8d9dcc8f23700de","head":{"label":"makingsensetraining:MLP-150-ImplementCoreDataStack","ref":"MLP-150-ImplementCoreDataStack","sha":"1593e25ae22ec82d677136efb8d9dcc8f23700de","user":{"login":"makingsensetraining","id":7902355,"avatar_url":"https://avatars2.githubusercontent.com/u/7902355?v=3","gravatar_id":"","url":"https://api.github.com/users/makingsensetraining","html_url":"https://github.com/makingsensetraining","followers_url":"https://api.github.com/users/makingsensetraining/followers","following_url":"https://api.github.com/users/makingsensetraining/following{/other_user}","gists_url":"https://api.github.com/users/makingsensetraining/gists{/gist_id}","starred_url":"https://api.github.com/users/makingsensetraining/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makingsensetraining/subscriptions","organizations_url":"https://api.github.com/users/makingsensetraining/orgs","repos_url":"https://api.github.com/users/makingsensetraining/repos","events_url":"https://api.github.com/users/makingsensetraining/events{/privacy}","received_events_url":"https://api.github.com/users/makingsensetraining/received_events","type":"Organization","site_admin":false},"repo":{"id":83568143,"name":"mobile-pocs","full_name":"makingsensetraining/mobile-pocs","owner":{"login":"makingsensetraining","id":7902355,"avatar_url":"https://avatars2.githubusercontent.com/u/7902355?v=3","gravatar_id":"","url":"https://api.github.com/users/makingsensetraining","html_url":"https://github.com/makingsensetraining","followers_url":"https://api.github.com/users/makingsensetraining/followers","following_url":"https://api.github.com/users/makingsensetraining/following{/other_user}","gists_url":"https://api.github.com/users/makingsensetraining/gists{/gist_id}","starred_url":"https://api.github.com/users/makingsensetraining/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makingsensetraining/subscriptions","organizations_url":"https://api.github.com/users/makingsensetraining/orgs","repos_url":"https://api.github.com/users/makingsensetraining/repos","events_url":"https://api.github.com/users/makingsensetraining/events{/privacy}","received_events_url":"https://api.github.com/users/makingsensetraining/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/makingsensetraining/mobile-pocs","description":null,"fork":false,"url":"https://api.github.com/repos/makingsensetraining/mobile-pocs","forks_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/forks","keys_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/teams","hooks_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/hooks","issue_events_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/events{/number}","events_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/events","assignees_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/assignees{/user}","branches_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/branches{/branch}","tags_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/tags","blobs_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/refs{/sha}","trees_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/statuses/{sha}","languages_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/languages","stargazers_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/stargazers","contributors_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/contributors","subscribers_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/subscribers","subscription_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/subscription","commits_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/commits{/sha}","git_commits_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/commits{/sha}","comments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/comments{/number}","issue_comment_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/comments{/number}","contents_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/contents/{+path}","compare_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/merges","archive_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/downloads","issues_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues{/number}","pulls_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls{/number}","milestones_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/milestones{/number}","notifications_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/labels{/name}","releases_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/releases{/id}","deployments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/deployments","created_at":"2017-03-01T15:11:07Z","updated_at":"2017-03-08T13:04:53Z","pushed_at":"2017-04-03T18:05:29Z","git_url":"git://github.com/makingsensetraining/mobile-pocs.git","ssh_url":"git@github.com:makingsensetraining/mobile-pocs.git","clone_url":"https://github.com/makingsensetraining/mobile-pocs.git","svn_url":"https://github.com/makingsensetraining/mobile-pocs","homepage":null,"size":9316,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":0,"default_branch":"develop"}},"base":{"label":"makingsensetraining:develop","ref":"develop","sha":"dd0a43dc3e2a9eebb4c68a9bea4064c40e23d395","user":{"login":"makingsensetraining","id":7902355,"avatar_url":"https://avatars2.githubusercontent.com/u/7902355?v=3","gravatar_id":"","url":"https://api.github.com/users/makingsensetraining","html_url":"https://github.com/makingsensetraining","followers_url":"https://api.github.com/users/makingsensetraining/followers","following_url":"https://api.github.com/users/makingsensetraining/following{/other_user}","gists_url":"https://api.github.com/users/makingsensetraining/gists{/gist_id}","starred_url":"https://api.github.com/users/makingsensetraining/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makingsensetraining/subscriptions","organizations_url":"https://api.github.com/users/makingsensetraining/orgs","repos_url":"https://api.github.com/users/makingsensetraining/repos","events_url":"https://api.github.com/users/makingsensetraining/events{/privacy}","received_events_url":"https://api.github.com/users/makingsensetraining/received_events","type":"Organization","site_admin":false},"repo":{"id":83568143,"name":"mobile-pocs","full_name":"makingsensetraining/mobile-pocs","owner":{"login":"makingsensetraining","id":7902355,"avatar_url":"https://avatars2.githubusercontent.com/u/7902355?v=3","gravatar_id":"","url":"https://api.github.com/users/makingsensetraining","html_url":"https://github.com/makingsensetraining","followers_url":"https://api.github.com/users/makingsensetraining/followers","following_url":"https://api.github.com/users/makingsensetraining/following{/other_user}","gists_url":"https://api.github.com/users/makingsensetraining/gists{/gist_id}","starred_url":"https://api.github.com/users/makingsensetraining/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makingsensetraining/subscriptions","organizations_url":"https://api.github.com/users/makingsensetraining/orgs","repos_url":"https://api.github.com/users/makingsensetraining/repos","events_url":"https://api.github.com/users/makingsensetraining/events{/privacy}","received_events_url":"https://api.github.com/users/makingsensetraining/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/makingsensetraining/mobile-pocs","description":null,"fork":false,"url":"https://api.github.com/repos/makingsensetraining/mobile-pocs","forks_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/forks","keys_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/teams","hooks_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/hooks","issue_events_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/events{/number}","events_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/events","assignees_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/assignees{/user}","branches_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/branches{/branch}","tags_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/tags","blobs_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/refs{/sha}","trees_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/statuses/{sha}","languages_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/languages","stargazers_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/stargazers","contributors_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/contributors","subscribers_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/subscribers","subscription_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/subscription","commits_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/commits{/sha}","git_commits_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/git/commits{/sha}","comments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/comments{/number}","issue_comment_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/comments{/number}","contents_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/contents/{+path}","compare_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/merges","archive_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/downloads","issues_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues{/number}","pulls_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls{/number}","milestones_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/milestones{/number}","notifications_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/labels{/name}","releases_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/releases{/id}","deployments_url":"https://api.github.com/repos/makingsensetraining/mobile-pocs/deployments","created_at":"2017-03-01T15:11:07Z","updated_at":"2017-03-08T13:04:53Z","pushed_at":"2017-04-03T18:05:29Z","git_url":"git://github.com/makingsensetraining/mobile-pocs.git","ssh_url":"git@github.com:makingsensetraining/mobile-pocs.git","clone_url":"https://github.com/makingsensetraining/mobile-pocs.git","svn_url":"https://github.com/makingsensetraining/mobile-pocs","homepage":null,"size":9316,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14"},"html":{"href":"https://github.com/makingsensetraining/mobile-pocs/pull/14"},"issue":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/14"},"comments":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/makingsensetraining/mobile-pocs/statuses/1593e25ae22ec82d677136efb8d9dcc8f23700de"}}}}
{"actor":{"display_login":"lpelizzaMS"}}