From 04adf36f44dac6b28aab7dfb97324f024acf3def Mon Sep 17 00:00:00 2001 From: Daniel Dahan Date: Mon, 14 Mar 2016 16:52:18 -0700 Subject: [PATCH] reduced code instantiation when passing contexts --- .../contents.xcworkspacedata | 10 +------ .../xcshareddata/Graph.xcscmblueprint | 30 +++++++++++++++++++ Graph.podspec | 2 +- .../xcshareddata/xcschemes/Graph OSX.xcscheme | 3 +- .../xcshareddata/xcschemes/Graph iOS.xcscheme | 3 +- Sources/Action.swift | 2 +- Sources/Entity.swift | 2 +- Sources/Graph.swift | 18 +++++------ Sources/GraphObject.swift | 3 +- Sources/GraphSearch.swift | 24 +++++++-------- Sources/GraphWatch.swift | 6 ++-- Sources/Info.plist | 2 +- Sources/ManagedAction.swift | 5 ++-- Sources/ManagedActionGroup.swift | 5 ++-- Sources/ManagedActionProperty.swift | 5 ++-- Sources/ManagedEntity.swift | 5 ++-- Sources/ManagedEntityGroup.swift | 5 ++-- Sources/ManagedEntityProperty.swift | 5 ++-- Sources/ManagedRelationship.swift | 5 ++-- Sources/ManagedRelationshipGroup.swift | 5 ++-- Sources/ManagedRelationshipProperty.swift | 5 ++-- Sources/Relationship.swift | 2 +- 22 files changed, 83 insertions(+), 69 deletions(-) create mode 100644 Examples/Graph.xcworkspace/xcshareddata/Graph.xcscmblueprint diff --git a/Examples/Graph.xcworkspace/contents.xcworkspacedata b/Examples/Graph.xcworkspace/contents.xcworkspacedata index 2849f189..bfb0fb88 100644 --- a/Examples/Graph.xcworkspace/contents.xcworkspacedata +++ b/Examples/Graph.xcworkspace/contents.xcworkspacedata @@ -6,21 +6,13 @@ + name = "Examples"> - - - - diff --git a/Examples/Graph.xcworkspace/xcshareddata/Graph.xcscmblueprint b/Examples/Graph.xcworkspace/xcshareddata/Graph.xcscmblueprint new file mode 100644 index 00000000..bbc25403 --- /dev/null +++ b/Examples/Graph.xcworkspace/xcshareddata/Graph.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "14FF5CD0A93F3CC14F0E8C5A4FD8ECB4A6DF5909", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "03C6D728E054A05A684543B0D508854F060D607A" : 0, + "14FF5CD0A93F3CC14F0E8C5A4FD8ECB4A6DF5909" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F41C22B4-E7B3-4518-A78B-4DA7005737D5", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "03C6D728E054A05A684543B0D508854F060D607A" : "Algorithm\/", + "14FF5CD0A93F3CC14F0E8C5A4FD8ECB4A6DF5909" : "Graph\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "Graph", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Examples\/Graph.xcworkspace", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/danieldahan:qX6787vF!b@github.com\/CosmicMind\/Algorithm.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "03C6D728E054A05A684543B0D508854F060D607A" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/danieldahan:qX6787vF!b@github.com\/CosmicMind\/Graph.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "14FF5CD0A93F3CC14F0E8C5A4FD8ECB4A6DF5909" + } + ] +} \ No newline at end of file diff --git a/Graph.podspec b/Graph.podspec index cd55d406..b5f88fb7 100755 --- a/Graph.podspec +++ b/Graph.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Graph' - s.version = '1.0.5' + s.version = '1.0.6' s.license = 'BSD' s.summary = 'An elegant data-driven framework for CoreData in Swift.' s.homepage = 'http://cosmicmind.io' diff --git a/Graph.xcodeproj/xcshareddata/xcschemes/Graph OSX.xcscheme b/Graph.xcodeproj/xcshareddata/xcschemes/Graph OSX.xcscheme index 34f5e9ad..095dee2b 100644 --- a/Graph.xcodeproj/xcshareddata/xcschemes/Graph OSX.xcscheme +++ b/Graph.xcodeproj/xcshareddata/xcschemes/Graph OSX.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/Graph.xcodeproj/xcshareddata/xcschemes/Graph iOS.xcscheme b/Graph.xcodeproj/xcshareddata/xcschemes/Graph iOS.xcscheme index e69c268b..eba69447 100644 --- a/Graph.xcodeproj/xcshareddata/xcschemes/Graph iOS.xcscheme +++ b/Graph.xcodeproj/xcshareddata/xcschemes/Graph iOS.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/Sources/Action.swift b/Sources/Action.swift index c341ee19..d1c41a0c 100644 --- a/Sources/Action.swift +++ b/Sources/Action.swift @@ -126,7 +126,7 @@ public class Action : NSObject, Comparable { /** :name: init */ - public convenience init(type: String) { + public required convenience init(type: String) { self.init(object: ManagedAction(type: type)) } diff --git a/Sources/Entity.swift b/Sources/Entity.swift index ae17817c..2d5b102f 100644 --- a/Sources/Entity.swift +++ b/Sources/Entity.swift @@ -168,7 +168,7 @@ public class Entity : NSObject, Comparable { /** :name: init */ - public convenience init(type: String) { + public required convenience init(type: String) { self.init(object: ManagedEntity(type: type)) } diff --git a/Sources/Graph.swift b/Sources/Graph.swift index 5c42367d..44b92261 100644 --- a/Sources/Graph.swift +++ b/Sources/Graph.swift @@ -147,7 +147,7 @@ public class Graph : NSObject { executed when the save operation is completed. */ public func asyncSave(completion: ((success: Bool, error: NSError?) -> Void)? = nil) { - if let p: NSManagedObjectContext = context { + if let p: NSManagedObjectContext = Graph.context { if p.hasChanges { p.performBlock { do { @@ -171,7 +171,7 @@ public class Graph : NSObject { executed when the save operation is completed. */ public func save(completion: ((success: Bool, error: NSError?) -> Void)? = nil) { - if let p: NSManagedObjectContext = context { + if let p: NSManagedObjectContext = Graph.context { if p.hasChanges { p.performBlockAndWait { do { @@ -209,11 +209,11 @@ public class Graph : NSObject { /** :name: context */ - internal var context: NSManagedObjectContext? { - dispatch_once(&GraphPrivateManagedObjectContext.onceToken) { [unowned self] in + internal static var context: NSManagedObjectContext? { + dispatch_once(&GraphPrivateManagedObjectContext.onceToken) { GraphPrivateManagedObjectContext.managedObjectContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType) GraphPrivateManagedObjectContext.managedObjectContext?.undoManager - GraphPrivateManagedObjectContext.managedObjectContext?.persistentStoreCoordinator = self.persistentStoreCoordinator + GraphPrivateManagedObjectContext.managedObjectContext?.persistentStoreCoordinator = Graph.persistentStoreCoordinator } return GraphPrivateManagedObjectContext.managedObjectContext } @@ -221,7 +221,7 @@ public class Graph : NSObject { // // :name: managedObjectModel // - internal var managedObjectModel: NSManagedObjectModel? { + internal static var managedObjectModel: NSManagedObjectModel? { dispatch_once(&GraphManagedObjectModel.onceToken) { GraphManagedObjectModel.managedObjectModel = NSManagedObjectModel() @@ -507,8 +507,8 @@ public class Graph : NSObject { // // :name: persistentStoreCoordinator // - internal var persistentStoreCoordinator: NSPersistentStoreCoordinator? { - dispatch_once(&GraphPersistentStoreCoordinator.onceToken) { [unowned self] in + internal static var persistentStoreCoordinator: NSPersistentStoreCoordinator? { + dispatch_once(&GraphPersistentStoreCoordinator.onceToken) { let directory: String = "Graph/default" File.createDirectory(File.documentDirectoryPath!, name: directory, withIntermediateDirectories: true, attributes: nil) { (success: Bool, error: NSError?) -> Void in if !success { @@ -516,7 +516,7 @@ public class Graph : NSObject { fatalError(e.localizedDescription) } } - let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel!) + let coordinator = NSPersistentStoreCoordinator(managedObjectModel: Graph.managedObjectModel!) do { try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: File.URL(.DocumentDirectory, path: "\(directory)/\(GraphUtility.storeName)"), options: nil) } catch { diff --git a/Sources/GraphObject.swift b/Sources/GraphObject.swift index d832c24c..b7fb7710 100644 --- a/Sources/GraphObject.swift +++ b/Sources/GraphObject.swift @@ -41,8 +41,7 @@ internal class GraphObject : NSManagedObject { // internal var worker: NSManagedObjectContext? { if nil == context { - let g: Graph = Graph() - context = g.context + context = Graph.context } return context } diff --git a/Sources/GraphSearch.swift b/Sources/GraphSearch.swift index 163ec42c..39163c27 100644 --- a/Sources/GraphSearch.swift +++ b/Sources/GraphSearch.swift @@ -66,7 +66,7 @@ public extension Graph { nodes[i] = Entity(object: v) continue } - } else if let v: ManagedEntity = context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedEntity { + } else if let v: ManagedEntity = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedEntity { if nil == seen.updateValue(true, forKey: v.id) { nodes[i] = Entity(object: v) continue @@ -80,7 +80,7 @@ public extension Graph { if let v: ManagedEntity = $0 as? ManagedEntity { return Entity(object: v) } - return Entity(object: context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedEntity) + return Entity(object: Graph.context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedEntity) } as Array } } @@ -120,7 +120,7 @@ public extension Graph { nodes[i] = Relationship(object: v) continue } - } else if let v: ManagedRelationship = context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedRelationship { + } else if let v: ManagedRelationship = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedRelationship { if nil == seen.updateValue(true, forKey: v.id) { nodes[i] = Relationship(object: v) continue @@ -134,7 +134,7 @@ public extension Graph { if let v: ManagedRelationship = $0 as? ManagedRelationship { return Relationship(object: v) } - return Relationship(object: context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedRelationship) + return Relationship(object: Graph.context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedRelationship) } as Array } } @@ -174,7 +174,7 @@ public extension Graph { nodes[i] = Action(object: v) continue } - } else if let v: ManagedAction = context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedAction { + } else if let v: ManagedAction = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedAction { if nil == seen.updateValue(true, forKey: v.id) { nodes[i] = Action(object: v) continue @@ -188,7 +188,7 @@ public extension Graph { if let v: ManagedAction = $0 as? ManagedAction { return Action(object: v) } - return Action(object: context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedAction) + return Action(object: Graph.context!.objectWithID($0["node"]! as! NSManagedObjectID) as! ManagedAction) } as Array } } @@ -200,7 +200,7 @@ public extension Graph { typesPredicate.append(NSPredicate(format: "type LIKE[cd] %@", v)) } - let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(typeDescriptionName, inManagedObjectContext: context!)! + let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(typeDescriptionName, inManagedObjectContext: Graph.context!)! let request: NSFetchRequest = NSFetchRequest() request.entity = entityDescription request.fetchBatchSize = batchSize @@ -208,7 +208,7 @@ public extension Graph { request.predicate = NSCompoundPredicate(orPredicateWithSubpredicates: typesPredicate) request.sortDescriptors = [NSSortDescriptor(key: "createdDate", ascending: true)] - return try? context!.executeFetchRequest(request) + return try? Graph.context!.executeFetchRequest(request) } internal func search(groupDescriptionName: String, groups: Array) -> Array? { @@ -218,7 +218,7 @@ public extension Graph { groupsPredicate.append(NSPredicate(format: "name LIKE[cd] %@", v)) } - let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(groupDescriptionName, inManagedObjectContext: context!)! + let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(groupDescriptionName, inManagedObjectContext: Graph.context!)! let request: NSFetchRequest = NSFetchRequest() request.entity = entityDescription request.fetchBatchSize = batchSize @@ -229,7 +229,7 @@ public extension Graph { request.predicate = NSCompoundPredicate(orPredicateWithSubpredicates: groupsPredicate) request.sortDescriptors = [NSSortDescriptor(key: "node.createdDate", ascending: true)] - return try? context!.executeFetchRequest(request) + return try? Graph.context!.executeFetchRequest(request) } internal func search(propertyDescriptionName: String, properties: Array<(key: String, value: AnyObject?)>) -> Array? { @@ -247,7 +247,7 @@ public extension Graph { } } - let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(propertyDescriptionName, inManagedObjectContext: context!)! + let entityDescription: NSEntityDescription = NSEntityDescription.entityForName(propertyDescriptionName, inManagedObjectContext: Graph.context!)! let request: NSFetchRequest = NSFetchRequest() request.entity = entityDescription request.fetchBatchSize = batchSize @@ -258,6 +258,6 @@ public extension Graph { request.predicate = NSCompoundPredicate(orPredicateWithSubpredicates: propertiesPredicate) request.sortDescriptors = [NSSortDescriptor(key: "node.createdDate", ascending: true)] - return try? context!.executeFetchRequest(request) + return try? Graph.context!.executeFetchRequest(request) } } diff --git a/Sources/GraphWatch.swift b/Sources/GraphWatch.swift index 5afefe89..d795d872 100644 --- a/Sources/GraphWatch.swift +++ b/Sources/GraphWatch.swift @@ -181,8 +181,8 @@ public extension Graph { // internal func prepareForObservation() { NSNotificationCenter.defaultCenter().removeObserver(self) - NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextDidSaveNotification, object: context) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "managedObjectContextDidSave:", name: NSManagedObjectContextDidSaveNotification, object: context) + NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextDidSaveNotification, object: Graph.context) + NSNotificationCenter.defaultCenter().addObserver(self, selector: "managedObjectContextDidSave:", name: NSManagedObjectContextDidSaveNotification, object: Graph.context) } // @@ -230,7 +230,7 @@ public extension Graph { save operation. */ private func notifyWatchers(notification: NSNotification) { - let moc: NSManagedObjectContext = context! + let moc: NSManagedObjectContext = Graph.context! moc.mergeChangesFromContextDidSaveNotification(notification) let userInfo: [NSObject : AnyObject]? = notification.userInfo diff --git a/Sources/Info.plist b/Sources/Info.plist index 0a07aa48..fd9c3cc3 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.5 + 1.0.6 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/ManagedAction.swift b/Sources/ManagedAction.swift index 68388c56..a1b06fc4 100644 --- a/Sources/ManagedAction.swift +++ b/Sources/ManagedAction.swift @@ -40,8 +40,7 @@ internal class ManagedAction : ManagedNode { :description: Initializes the Model Object with e a given type. */ internal convenience init(type: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) nodeClass = NodeClass.Action.rawValue self.type = type createdDate = NSDate() @@ -49,7 +48,7 @@ internal class ManagedAction : ManagedNode { groupSet = NSSet() subjectSet = NSSet() objectSet = NSSet() - context = g.context + context = Graph.context } /** diff --git a/Sources/ManagedActionGroup.swift b/Sources/ManagedActionGroup.swift index 21c67c01..160b8474 100644 --- a/Sources/ManagedActionGroup.swift +++ b/Sources/ManagedActionGroup.swift @@ -39,9 +39,8 @@ internal class ManagedActionGroup : ManagedNodeGroup { :description: Initializer for the Model Object. */ internal convenience init(name: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionGroupDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionGroupDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name - context = g.context + context = Graph.context } } diff --git a/Sources/ManagedActionProperty.swift b/Sources/ManagedActionProperty.swift index 4047e5ff..00df30d5 100644 --- a/Sources/ManagedActionProperty.swift +++ b/Sources/ManagedActionProperty.swift @@ -39,10 +39,9 @@ internal class ManagedActionProperty : ManagedNodeProperty { :description: Initializer for the Model Object. */ internal convenience init(name: String, object: AnyObject) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionPropertyDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.actionPropertyDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name self.object = object - context = g.context + context = Graph.context } } diff --git a/Sources/ManagedEntity.swift b/Sources/ManagedEntity.swift index 524ec1c6..8a06b553 100644 --- a/Sources/ManagedEntity.swift +++ b/Sources/ManagedEntity.swift @@ -41,8 +41,7 @@ internal class ManagedEntity : ManagedNode { :description: Initializes the Model Object with e a given type. */ internal convenience init(type: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) nodeClass = NodeClass.Entity.rawValue self.type = type createdDate = NSDate() @@ -52,7 +51,7 @@ internal class ManagedEntity : ManagedNode { actionObjectSet = NSSet() relationshipSubjectSet = NSSet() relationshipObjectSet = NSSet() - context = g.context + context = Graph.context } /** diff --git a/Sources/ManagedEntityGroup.swift b/Sources/ManagedEntityGroup.swift index 822eaa39..33a9e01c 100644 --- a/Sources/ManagedEntityGroup.swift +++ b/Sources/ManagedEntityGroup.swift @@ -39,9 +39,8 @@ internal class ManagedEntityGroup : ManagedNodeGroup { :description: Initializer for the Model Object. */ internal convenience init(name: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityGroupDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityGroupDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name - context = g.context + context = Graph.context } } diff --git a/Sources/ManagedEntityProperty.swift b/Sources/ManagedEntityProperty.swift index c574c672..dd29d9fe 100644 --- a/Sources/ManagedEntityProperty.swift +++ b/Sources/ManagedEntityProperty.swift @@ -38,10 +38,9 @@ internal class ManagedEntityProperty : ManagedNodeProperty { :name: init */ internal convenience init(name: String, object: AnyObject) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityPropertyDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.entityPropertyDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name self.object = object - context = g.context + context = Graph.context } } diff --git a/Sources/ManagedRelationship.swift b/Sources/ManagedRelationship.swift index b9d4e050..5f91bd14 100644 --- a/Sources/ManagedRelationship.swift +++ b/Sources/ManagedRelationship.swift @@ -40,8 +40,7 @@ internal class ManagedRelationship : ManagedNode { :description: Initializes the Model Object with e a given type. */ internal convenience init(type: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) nodeClass = NodeClass.Relationship.rawValue self.type = type createdDate = NSDate() @@ -49,7 +48,7 @@ internal class ManagedRelationship : ManagedNode { groupSet = NSSet() subject = nil object = nil - context = g.context + context = Graph.context } /** diff --git a/Sources/ManagedRelationshipGroup.swift b/Sources/ManagedRelationshipGroup.swift index 3c016f85..818c9536 100644 --- a/Sources/ManagedRelationshipGroup.swift +++ b/Sources/ManagedRelationshipGroup.swift @@ -39,9 +39,8 @@ internal class ManagedRelationshipGroup : ManagedNodeGroup { :description: Initializer for the Model Object. */ internal convenience init(name: String) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipGroupDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipGroupDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name - context = g.context + context = Graph.context } } diff --git a/Sources/ManagedRelationshipProperty.swift b/Sources/ManagedRelationshipProperty.swift index cb1ad53b..c45b2126 100644 --- a/Sources/ManagedRelationshipProperty.swift +++ b/Sources/ManagedRelationshipProperty.swift @@ -39,10 +39,9 @@ internal class ManagedRelationshipProperty : ManagedNodeProperty { :description: Initializer for the Model Object. */ internal convenience init(name: String, object: AnyObject) { - let g: Graph = Graph() - self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipPropertyDescriptionName, inManagedObjectContext: g.context!)!, insertIntoManagedObjectContext: g.context) + self.init(entity: NSEntityDescription.entityForName(GraphUtility.relationshipPropertyDescriptionName, inManagedObjectContext: Graph.context!)!, insertIntoManagedObjectContext: Graph.context) self.name = name self.object = object - context = g.context + context = Graph.context } } diff --git a/Sources/Relationship.swift b/Sources/Relationship.swift index 0f2a86e7..0f084314 100644 --- a/Sources/Relationship.swift +++ b/Sources/Relationship.swift @@ -123,7 +123,7 @@ public class Relationship : NSObject, Comparable { /** :name: init */ - public convenience init(type: String) { + public required convenience init(type: String) { self.init(object: ManagedRelationship(type: type)) }