From 97856520d1fe931b7fbf237a68a803ed7c66416d Mon Sep 17 00:00:00 2001 From: Hardik Date: Thu, 29 Sep 2016 11:28:14 +0530 Subject: [PATCH 1/2] Swift 3 NSDate to Date Swift 3 Making Optional first parameters in one to many relation --- mogenerator.m | 3 +++ templates/machine.swift.motemplate | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index 95570a53..2cd89ef4 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -540,6 +540,9 @@ - (NSString*)objectAttributeClassName { if (gSwift && [result isEqualToString:@"NSString"]) { result = @"String"; } + if (gSwift && [result isEqualToString:@"NSDate"]) { + result = @"Date"; + } return result; } - (NSArray*)objectAttributeTransformableProtocols { diff --git a/templates/machine.swift.motemplate b/templates/machine.swift.motemplate index d066485e..e3a5a0df 100644 --- a/templates/machine.swift.motemplate +++ b/templates/machine.swift.motemplate @@ -178,25 +178,25 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { <$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$> extension _<$sanitizedManagedObjectClassName$> { - open func add<$Relationship.name.initialCapitalString$>(objects: <$Relationship.immutableCollectionClassName$>) { + open func add<$Relationship.name.initialCapitalString$>(_ objects: <$Relationship.immutableCollectionClassName$>) { let mutable = self.<$Relationship.name$>.mutableCopy() as! NSMutable<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set mutable.union(objects<$if !Relationship.jr_isOrdered$> as Set<$endif$>) self.<$Relationship.name$> = mutable.copy() as! NS<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set } - open func remove<$Relationship.name.initialCapitalString$>(objects: <$Relationship.immutableCollectionClassName$>) { + open func remove<$Relationship.name.initialCapitalString$>(_ objects: <$Relationship.immutableCollectionClassName$>) { let mutable = self.<$Relationship.name$>.mutableCopy() as! NSMutable<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set mutable.minus(objects<$if !Relationship.jr_isOrdered$> as Set<$endif$>) self.<$Relationship.name$> = mutable.copy() as! NS<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set } - open func add<$Relationship.name.initialCapitalString$>Object(value: <$Relationship.destinationEntity.sanitizedManagedObjectClassName$>) { + open func add<$Relationship.name.initialCapitalString$>Object(_ value: <$Relationship.destinationEntity.sanitizedManagedObjectClassName$>) { let mutable = self.<$Relationship.name$>.mutableCopy() as! NSMutable<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set mutable.add(value) self.<$Relationship.name$> = mutable.copy() as! NS<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set } - open func remove<$Relationship.name.initialCapitalString$>Object(value: <$Relationship.destinationEntity.sanitizedManagedObjectClassName$>) { + open func remove<$Relationship.name.initialCapitalString$>Object(_ value: <$Relationship.destinationEntity.sanitizedManagedObjectClassName$>) { let mutable = self.<$Relationship.name$>.mutableCopy() as! NSMutable<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set mutable.remove(value) self.<$Relationship.name$> = mutable.copy() as! NS<$if Relationship.jr_isOrdered$>Ordered<$endif$>Set From f24fcd4605238729c4ddefc688bb5e1c0143d7d1 Mon Sep 17 00:00:00 2001 From: Hardik Date: Mon, 3 Oct 2016 16:05:48 +0530 Subject: [PATCH 2/2] Template Updated With Latest OS X Swift 3 Changes Test Passed --- templates/machine.swift.motemplate | 43 +-- .../MogenSwiftTest.xcodeproj/project.pbxproj | 29 +- .../MogenSwiftTest/AppDelegate.swift | 259 +++++++++--------- test/MogenSwiftTest/MogenSwiftTest/Info.plist | 2 +- .../MogenSwiftTest/MyEntityMO.swift | 1 + .../MogenSwiftTest/UnorderedToManyDstMO.swift | 1 + .../MogenSwiftTest/UnorderedToManySrcMO.swift | 1 + .../MogenSwiftTest/_MyEntityMO.swift | 10 +- .../_UnorderedToManyDstMO.swift | 10 +- .../_UnorderedToManySrcMO.swift | 57 ++-- test/MogenSwiftTest/MogenSwiftTest/main.swift | 2 +- .../MogenSwiftTestTests/Info.plist | 2 +- .../MogenSwiftTestTests.swift | 10 +- test/swift/Gender.swift | 4 +- test/swift/MyBaseClass.swift | 2 +- test/swift/main.swift | 14 +- 16 files changed, 237 insertions(+), 210 deletions(-) diff --git a/templates/machine.swift.motemplate b/templates/machine.swift.motemplate index e3a5a0df..eb40d9e0 100644 --- a/templates/machine.swift.motemplate +++ b/templates/machine.swift.motemplate @@ -63,9 +63,9 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { <$if Attribute.isReadonly$> open var <$Attribute.name$>: NSNumber? { - self.willAccessValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) - let <$Attribute.name$> = self.primitiveValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? NSNumber - self.didAccessValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) + self.willAccessValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) + let <$Attribute.name$> = self.primitiveValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? NSNumber + self.didAccessValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) return <$Attribute.name$> } <$else$> @@ -76,9 +76,9 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { <$if Attribute.isReadonly$> open var <$Attribute.name$>: <$Attribute.objectAttributeType$><$if Attribute.isOptional$>?<$endif$> { - self.willAccessValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) - let <$Attribute.name$> = self.primitiveValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? <$Attribute.objectAttributeType$> - self.didAccessValueForKey(<$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) + self.willAccessValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) + let <$Attribute.name$> =self.primitiveValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? <$Attribute.objectAttributeType$> + self.didAccessValue(forKey: <$sanitizedManagedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) return <$Attribute.name$> } <$else$> @@ -107,11 +107,11 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { <$foreach FetchRequest prettyFetchRequests do$> <$if FetchRequest.singleResult$> - class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>) -> AnyObject? { - return self.fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.name$><$endforeach do2$>, error: nil) + class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>) -> Any? { + return self.fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: managedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.name$><$endforeach do2$>, error: nil) } - class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>, error outError: NSErrorPointer) -> AnyObject? { + class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>, error outError: NSErrorPointer) -> Any? { guard let psc = managedObjectContext.persistentStoreCoordinator else { return nil } let model = psc.managedObjectModel let substitutionVariables = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$> @@ -119,14 +119,14 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { <$endforeach do2$><$endif$> ] - guard let fetchRequest = model.fetchRequestFromTemplateWithName("<$FetchRequest.name$>", substitutionVariables: substitutionVariables) else { + guard let fetchRequest = model.fetchRequestFromTemplate(withName: "<$FetchRequest.name$>", substitutionVariables: substitutionVariables) else { assert(false, "Can't find fetch request named \"<$FetchRequest.name$>\".") return nil } - var result: AnyObject? = nil + var result: Any? = nil do { - let results = try managedObjectContext.executeFetchRequest(fetchRequest) + let results = try managedObjectContext.fetch(fetchRequest) switch results.count { case 0: // Nothing found matching the fetch request. That's cool, though: we'll just return nil. @@ -143,23 +143,24 @@ open class _<$sanitizedManagedObjectClassName$>: NSManagedObject { return result } <$else$> - class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>) -> [AnyObject]? { - return self.fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.name$><$endforeach do2$>, error: nil) + class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>) -> [Any]? { + return self.fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: managedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.name$><$endforeach do2$>, error: nil) } - class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>, error outError: NSErrorPointer) -> [AnyObject]? { + class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>, error outError: NSErrorPointer) -> [Any]? { guard let psc = managedObjectContext.persistentStoreCoordinator else { return nil } let model = psc.managedObjectModel - let substitutionVariables : [String : AnyObject] = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$> + let substitutionVariables : [String : Any] = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$> "<$Binding.name$>": <$Binding.name$>, <$endforeach do2$><$else$>:<$endif$>] - let fetchRequest = model.fetchRequestFromTemplateWithName("<$FetchRequest.name$>", substitutionVariables: substitutionVariables) - assert(fetchRequest != nil, "Can't find fetch request named \"<$FetchRequest.name$>\".") - - var results = Array() + guard let fetchRequest = model.fetchRequestFromTemplate(withName: "<$FetchRequest.name$>", substitutionVariables: substitutionVariables) else { + assert(false, "Can't find fetch request named \"<$FetchRequest.name$>\".") + return nil + } + var results = Array() do { - results = try managedObjectContext.executeFetchRequest(fetchRequest!) + results = try managedObjectContext.fetch(fetchRequest) } catch { print("Error executing fetch request: \(error)") } diff --git a/test/MogenSwiftTest/MogenSwiftTest.xcodeproj/project.pbxproj b/test/MogenSwiftTest/MogenSwiftTest.xcodeproj/project.pbxproj index 90a9a423..07105a23 100644 --- a/test/MogenSwiftTest/MogenSwiftTest.xcodeproj/project.pbxproj +++ b/test/MogenSwiftTest/MogenSwiftTest.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 796DBE22196F2D9C004EAA15 /* MyEntityMO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796DBE1C196F2D9C004EAA15 /* MyEntityMO.swift */; }; 796DBE23196F2D9C004EAA15 /* UnorderedToManyDstMO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796DBE1D196F2D9C004EAA15 /* UnorderedToManyDstMO.swift */; }; 796DBE24196F2D9C004EAA15 /* UnorderedToManySrcMO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796DBE1E196F2D9C004EAA15 /* UnorderedToManySrcMO.swift */; }; - 79F9CECF196F146600D9BF82 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F9CECE196F146600D9BF82 /* main.swift */; }; 79F9CED1196F146600D9BF82 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F9CED0196F146600D9BF82 /* AppDelegate.swift */; }; 79F9CED4196F146600D9BF82 /* MogenSwiftTest.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 79F9CED2196F146600D9BF82 /* MogenSwiftTest.xcdatamodeld */; }; 79F9CED6196F146600D9BF82 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 79F9CED5196F146600D9BF82 /* Images.xcassets */; }; @@ -40,7 +39,6 @@ 796DBE1E196F2D9C004EAA15 /* UnorderedToManySrcMO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnorderedToManySrcMO.swift; sourceTree = ""; }; 79F9CEC9196F146600D9BF82 /* MogenSwiftTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MogenSwiftTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 79F9CECD196F146600D9BF82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 79F9CECE196F146600D9BF82 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 79F9CED0196F146600D9BF82 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 79F9CED3196F146600D9BF82 /* MogenSwiftTest.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MogenSwiftTest.xcdatamodel; sourceTree = ""; }; 79F9CED5196F146600D9BF82 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -103,7 +101,6 @@ isa = PBXGroup; children = ( 79F9CECD196F146600D9BF82 /* Info.plist */, - 79F9CECE196F146600D9BF82 /* main.swift */, ); name = "Supporting Files"; sourceTree = ""; @@ -183,14 +180,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0600; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Jonathan 'Wolf' Rentzsch"; TargetAttributes = { 79F9CEC8196F146600D9BF82 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; 79F9CEDD196F146600D9BF82 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; + ProvisioningStyle = Automatic; TestTargetID = 79F9CEC8196F146600D9BF82; }; }; @@ -244,7 +244,6 @@ 796DBE24196F2D9C004EAA15 /* UnorderedToManySrcMO.swift in Sources */, 796DBE20196F2D9C004EAA15 /* _UnorderedToManyDstMO.swift in Sources */, 796DBE23196F2D9C004EAA15 /* UnorderedToManyDstMO.swift in Sources */, - 79F9CECF196F146600D9BF82 /* main.swift in Sources */, 796DBE1F196F2D9C004EAA15 /* _MyEntityMO.swift in Sources */, 79F9CED4196F146600D9BF82 /* MogenSwiftTest.xcdatamodeld in Sources */, ); @@ -293,15 +292,19 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -335,8 +338,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -345,6 +350,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -354,6 +360,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; @@ -362,9 +369,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; INFOPLIST_FILE = MogenSwiftTest/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rentzsch.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -373,9 +383,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; INFOPLIST_FILE = MogenSwiftTest/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rentzsch.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -383,6 +396,7 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MogenSwiftTest.app/Contents/MacOS/MogenSwiftTest"; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", @@ -394,7 +408,9 @@ ); INFOPLIST_FILE = MogenSwiftTestTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rentzsch.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUNDLE_LOADER)"; }; name = Debug; @@ -403,6 +419,7 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MogenSwiftTest.app/Contents/MacOS/MogenSwiftTest"; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", @@ -410,7 +427,9 @@ ); INFOPLIST_FILE = MogenSwiftTestTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rentzsch.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUNDLE_LOADER)"; }; name = Release; diff --git a/test/MogenSwiftTest/MogenSwiftTest/AppDelegate.swift b/test/MogenSwiftTest/MogenSwiftTest/AppDelegate.swift index 8208996b..8d1f4b7f 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/AppDelegate.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/AppDelegate.swift @@ -7,167 +7,164 @@ // import Cocoa - +@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - - @IBOutlet var window: NSWindow? - - @IBAction func saveAction(sender: AnyObject) { - // Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. - var error: NSError? = nil - - if let moc = self.managedObjectContext { - if !moc.commitEditing() { - println("\(NSStringFromClass(self.dynamicType)) unable to commit editing before saving") - } - if !moc.save(&error) { - NSApplication.sharedApplication().presentError(error!) - } - } - } - - var applicationFilesDirectory: NSURL { - // Returns the directory the application uses to store the Core Data store file. This code uses a directory named "com.rentzsch.MogenSwiftTest" in the user's Application Support directory. - let fileManager = NSFileManager.defaultManager() - let urls = fileManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask) - let appSupportURL: AnyObject = urls[urls.count - 1] - return appSupportURL.URLByAppendingPathComponent("com.rentzsch.MogenSwiftTest") + + + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application } - - var managedObjectModel: NSManagedObjectModel { - // Creates if necessary and returns the managed object model for the application. - if let mom = _managedObjectModel { - return mom - } - - let modelURL = NSBundle.mainBundle().URLForResource("MogenSwiftTest", withExtension: "momd") - _managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL!) - return _managedObjectModel! + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application } - var _managedObjectModel: NSManagedObjectModel? = nil - - var persistentStoreCoordinator: NSPersistentStoreCoordinator? { - // Returns the persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) - if let psc = _persistentStoreCoordinator { - return psc - } - - let mom = self.managedObjectModel - - let fileManager = NSFileManager.defaultManager() - let applicationFilesDirectory = self.applicationFilesDirectory - var error: NSError? = nil - - let optProperties: NSDictionary? = applicationFilesDirectory.resourceValuesForKeys([NSURLIsDirectoryKey], error: &error) + + // MARK: - Core Data stack + + lazy var applicationDocumentsDirectory: Foundation.URL = { + // The directory the application uses to store the Core Data store file. This code uses a directory named "com.apple.toolsQA.CocoaApp_CD" in the user's Application Support directory. + let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) + let appSupportURL = urls[urls.count - 1] + return appSupportURL.appendingPathComponent("com.apple.toolsQA.CocoaApp_CD") + }() + + lazy var managedObjectModel: NSManagedObjectModel = { + // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. + let modelURL = Bundle.main.url(forResource: "test", withExtension: "momd")! + return NSManagedObjectModel(contentsOf: modelURL)! + }() + + lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = { + // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. + let fileManager = FileManager.default + var failError: NSError? = nil + var shouldFail = false + var failureReason = "There was an error creating or loading the application's saved data." - if let properties = optProperties { - if !properties[NSURLIsDirectoryKey]!.boolValue { - // Customize and localize this error. - let failureDescription = "Expected a folder to store application data, found a file \(applicationFilesDirectory.path)." - var errorDict = [NSObject : AnyObject ]() - errorDict[NSLocalizedDescriptionKey] = failureDescription - error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 101, userInfo: errorDict) - - NSApplication.sharedApplication().presentError(error!) - return nil - } - } else { - var ok = false - if error!.code == NSFileReadNoSuchFileError { - ok = fileManager.createDirectoryAtPath(applicationFilesDirectory.path!, withIntermediateDirectories: true, attributes: nil, error: &error) + // Make sure the application files directory is there + do { + let properties = try self.applicationDocumentsDirectory.resourceValues(forKeys: [URLResourceKey.isDirectoryKey]) + if !properties.isDirectory! { + failureReason = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)." + shouldFail = true } - if !ok { - NSApplication.sharedApplication().presentError(error!) - return nil + } catch { + let nserror = error as NSError + if nserror.code == NSFileReadNoSuchFileError { + do { + try fileManager.createDirectory(atPath: self.applicationDocumentsDirectory.path, withIntermediateDirectories: true, attributes: nil) + } catch { + failError = nserror + } + } else { + failError = nserror } } - let url = applicationFilesDirectory.URLByAppendingPathComponent("MogenSwiftTest.storedata") - var coordinator = NSPersistentStoreCoordinator(managedObjectModel: mom) - if coordinator.addPersistentStoreWithType(NSXMLStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil { - NSApplication.sharedApplication().presentError(error!) - return nil + // Create the coordinator and store + var coordinator: NSPersistentStoreCoordinator? = nil + if failError == nil { + coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) + let url = self.applicationDocumentsDirectory.appendingPathComponent("test.storedata") + do { + try coordinator!.addPersistentStore(ofType: NSXMLStoreType, configurationName: nil, at: url, options: nil) + } catch { + // Replace this implementation with code to handle the error appropriately. + + /* + Typical reasons for an error here include: + * The persistent store is not accessible, due to permissions or data protection when the device is locked. + * The device is out of space. + * The store could not be migrated to the current model version. + Check the error message to determine what the actual problem was. + */ + failError = error as NSError + } } - _persistentStoreCoordinator = coordinator - return _persistentStoreCoordinator - } - var _persistentStoreCoordinator: NSPersistentStoreCoordinator? = nil - - var managedObjectContext: NSManagedObjectContext? { - // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) - if let moc = _managedObjectContext { - return moc + if shouldFail || (failError != nil) { + // Report any error we got. + if let error = failError { + NSApplication.shared().presentError(error) + fatalError("Unresolved error: \(error), \(error.userInfo)") + } + fatalError("Unsresolved error: \(failureReason)") + } else { + return coordinator! } - + }() + + lazy var managedObjectContext: NSManagedObjectContext = { + // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail. let coordinator = self.persistentStoreCoordinator - if !(coordinator != nil) { - var errorDict = [NSObject : AnyObject ]() - errorDict[NSLocalizedDescriptionKey] = "Failed to initialize the store" - errorDict[NSLocalizedFailureReasonErrorKey] = "There was an error building up the data file." - let error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: errorDict) - NSApplication.sharedApplication().presentError(error) - return nil + var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) + managedObjectContext.persistentStoreCoordinator = coordinator + return managedObjectContext + }() + + // MARK: - Core Data Saving and Undo support + + @IBAction func saveAction(_ sender: AnyObject?) { + // Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. + if !managedObjectContext.commitEditing() { + NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing before saving") + } + if managedObjectContext.hasChanges { + do { + try managedObjectContext.save() + } catch { + let nserror = error as NSError + NSApplication.shared().presentError(nserror) + } } - _managedObjectContext = NSManagedObjectContext() - _managedObjectContext!.persistentStoreCoordinator = coordinator! - - return _managedObjectContext } - var _managedObjectContext: NSManagedObjectContext? = nil - - func windowWillReturnUndoManager(window: NSWindow?) -> NSUndoManager? { + + func windowWillReturnUndoManager(window: NSWindow) -> UndoManager? { // Returns the NSUndoManager for the application. In this case, the manager returned is that of the managed object context for the application. - if let moc = self.managedObjectContext { - return moc.undoManager - } else { - return nil - } + return managedObjectContext.undoManager } - - func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply { + + func applicationShouldTerminate(_ sender: NSApplication) -> NSApplicationTerminateReply { // Save changes in the application's managed object context before the application terminates. - if !(_managedObjectContext != nil) { - // Accesses the underlying stored property because we don't want to cause the lazy initialization - return .TerminateNow - } - let moc = self.managedObjectContext! - if !moc.commitEditing() { - println("\(NSStringFromClass(self.dynamicType)) unable to commit editing to terminate") - return .TerminateCancel + if !managedObjectContext.commitEditing() { + NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate") + return .terminateCancel } - if !moc.hasChanges { - return .TerminateNow + if !managedObjectContext.hasChanges { + return .terminateNow } - var error: NSError? = nil - if !moc.save(&error) { - // Customize this code block to include application-specific recovery steps. - let result = sender.presentError(error!) + do { + try managedObjectContext.save() + } catch { + let nserror = error as NSError + // Customize this code block to include application-specific recovery steps. + let result = sender.presentError(nserror) if (result) { - return .TerminateCancel + return .terminateCancel } - - let question = "Could not save changes while quitting. Quit anyway?" // NSLocalizedString(@"Could not save changes while quitting. Quit anyway?", @"Quit without saves error question message") - let info = "Quitting now will lose any changes you have made since the last successful save" // NSLocalizedString(@"Quitting now will lose any changes you have made since the last successful save", @"Quit without saves error question info"); - let quitButton = "Quit anyway" // NSLocalizedString(@"Quit anyway", @"Quit anyway button title") - let cancelButton = "Cancel" // NSLocalizedString(@"Cancel", @"Cancel button title") + + let question = NSLocalizedString("Could not save changes while quitting. Quit anyway?", comment: "Quit without saves error question message") + let info = NSLocalizedString("Quitting now will lose any changes you have made since the last successful save", comment: "Quit without saves error question info"); + let quitButton = NSLocalizedString("Quit anyway", comment: "Quit anyway button title") + let cancelButton = NSLocalizedString("Cancel", comment: "Cancel button title") let alert = NSAlert() alert.messageText = question alert.informativeText = info - alert.addButtonWithTitle(quitButton) - alert.addButtonWithTitle(cancelButton) - + alert.addButton(withTitle: quitButton) + alert.addButton(withTitle: cancelButton) + let answer = alert.runModal() - if answer == NSAlertFirstButtonReturn { - return .TerminateCancel + if answer == NSAlertSecondButtonReturn { + return .terminateCancel } } - - return .TerminateNow + // If we got here, it is time to quit. + return .terminateNow } - + } diff --git a/test/MogenSwiftTest/MogenSwiftTest/Info.plist b/test/MogenSwiftTest/MogenSwiftTest/Info.plist index 4c1c58ec..7f6b8796 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/Info.plist +++ b/test/MogenSwiftTest/MogenSwiftTest/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - com.rentzsch.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/MyEntityMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/MyEntityMO.swift index 954d972e..529337e5 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/MyEntityMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/MyEntityMO.swift @@ -1,3 +1,4 @@ +import Foundation @objc class MyEntityMO: _MyEntityMO { diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManyDstMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManyDstMO.swift index e381a612..d38e71a3 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManyDstMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManyDstMO.swift @@ -1,3 +1,4 @@ +import Foundation @objc class UnorderedToManyDstMO: _UnorderedToManyDstMO { diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManySrcMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManySrcMO.swift index 15d5ee62..c88e52eb 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManySrcMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/UnorderedToManySrcMO.swift @@ -1,3 +1,4 @@ +import Foundation @objc class UnorderedToManySrcMO: _UnorderedToManySrcMO { diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_MyEntityMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_MyEntityMO.swift index 47fd71f6..db7848c7 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_MyEntityMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_MyEntityMO.swift @@ -17,19 +17,19 @@ class _MyEntityMO: NSManagedObject { return "MyEntity" } - class func entity(managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { - return NSEntityDescription.entityForName(self.entityName(), inManagedObjectContext: managedObjectContext); + class func entity(_ managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { + return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext); } /// pragma mark - Life cycle methods - override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) { - super.init(entity: entity, insertIntoManagedObjectContext: context) + override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) { + super.init(entity: entity, insertInto: context) } convenience init(managedObjectContext: NSManagedObjectContext!) { let entity = _MyEntityMO.entity(managedObjectContext) - self.init(entity: entity, insertIntoManagedObjectContext: managedObjectContext) + self.init(entity: entity!, insertInto: managedObjectContext) } /// pragma mark - Properties diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManyDstMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManyDstMO.swift index 7fd94715..de1d2884 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManyDstMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManyDstMO.swift @@ -20,19 +20,19 @@ class _UnorderedToManyDstMO: NSManagedObject { return "UnorderedToManyDst" } - class func entity(managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { - return NSEntityDescription.entityForName(self.entityName(), inManagedObjectContext: managedObjectContext); + class func entity(_ managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { + return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext); } /// pragma mark - Life cycle methods - override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) { - super.init(entity: entity, insertIntoManagedObjectContext: context) + override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) { + super.init(entity: entity, insertInto: context) } convenience init(managedObjectContext: NSManagedObjectContext!) { let entity = _UnorderedToManyDstMO.entity(managedObjectContext) - self.init(entity: entity, insertIntoManagedObjectContext: managedObjectContext) + self.init(entity: entity!, insertInto: managedObjectContext) } /// pragma mark - Properties diff --git a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManySrcMO.swift b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManySrcMO.swift index b036c933..644f5b4f 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManySrcMO.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManySrcMO.swift @@ -20,19 +20,19 @@ class _UnorderedToManySrcMO: NSManagedObject { return "UnorderedToManySrc" } - class func entity(managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { - return NSEntityDescription.entityForName(self.entityName(), inManagedObjectContext: managedObjectContext); + class func entity(_ managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { + return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext); } /// pragma mark - Life cycle methods - override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) { - super.init(entity: entity, insertIntoManagedObjectContext: context) + override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) { + super.init(entity: entity, insertInto: context) } convenience init(managedObjectContext: NSManagedObjectContext!) { let entity = _UnorderedToManySrcMO.entity(managedObjectContext) - self.init(entity: entity, insertIntoManagedObjectContext: managedObjectContext) + self.init(entity: entity!, insertInto: managedObjectContext) } /// pragma mark - Properties @@ -48,53 +48,60 @@ class _UnorderedToManySrcMO: NSManagedObject { var relationship: NSSet func relationshipSet() -> NSMutableSet! { - self.willAccessValueForKey("relationship") + self.willAccessValue(forKey: "relationship") - let result = self.mutableSetValueForKey("relationship") + let result = self.mutableSetValue(forKey: "relationship") - self.didAccessValueForKey("relationship") + self.didAccessValue(forKey: "relationship") return result } - class func fetchAllUnorderedToManySrcs(managedObjectContext: NSManagedObjectContext!) -> [AnyObject] { + class func fetchAllUnorderedToManySrcs(_ managedObjectContext: NSManagedObjectContext!) -> [AnyObject] { return self.fetchAllUnorderedToManySrcs(managedObjectContext, error: nil) } - class func fetchAllUnorderedToManySrcs(managedObjectContext: NSManagedObjectContext!, error outError: NSErrorPointer) -> [AnyObject] { + class func fetchAllUnorderedToManySrcs(_ managedObjectContext: NSManagedObjectContext!, error outError: NSErrorPointer) -> [AnyObject] { let model = managedObjectContext.persistentStoreCoordinator!.managedObjectModel - let substitutionVariables = [:] + let substitutionVariables:[String : Any] = [:] - let fetchRequest = model.fetchRequestFromTemplateWithName("allUnorderedToManySrcs", substitutionVariables: substitutionVariables as [NSObject : AnyObject]) + let fetchRequest = model.fetchRequestFromTemplate(withName: "allUnorderedToManySrcs", substitutionVariables: substitutionVariables ) assert(fetchRequest != nil, "Can't find fetch request named \"allUnorderedToManySrcs\".") - var error: NSError? = nil - let results = managedObjectContext.executeFetchRequest(fetchRequest!, error: &error) + var results:[AnyObject] = [] + do { + + + results = try managedObjectContext.fetch(fetchRequest!) - if (error != nil) { - outError.memory = error + }catch let e { + outError?.pointee = e as NSError? + + } - return results! + + + return results } } extension _UnorderedToManySrcMO { - func addRelationship(objects: NSSet) { - self.relationshipSet().unionSet(objects as Set) + func addRelationship(_ objects: NSSet) { + self.relationshipSet().union(objects as Set) } - func removeRelationship(objects: NSSet) { - self.relationshipSet().minusSet(objects as Set) + func removeRelationship(_ objects: NSSet) { + self.relationshipSet().minus(objects as Set) } - func addRelationshipObject(value: UnorderedToManyDstMO!) { - self.relationshipSet().addObject(value) + func addRelationshipObject(_ value: UnorderedToManyDstMO!) { + self.relationshipSet().add(value) } - func removeRelationshipObject(value: UnorderedToManyDstMO!) { - self.relationshipSet().removeObject(value) + func removeRelationshipObject(_ value: UnorderedToManyDstMO!) { + self.relationshipSet().remove(value) } } diff --git a/test/MogenSwiftTest/MogenSwiftTest/main.swift b/test/MogenSwiftTest/MogenSwiftTest/main.swift index 1eb8c819..e9a3ba6d 100644 --- a/test/MogenSwiftTest/MogenSwiftTest/main.swift +++ b/test/MogenSwiftTest/MogenSwiftTest/main.swift @@ -8,4 +8,4 @@ import Cocoa -NSApplicationMain(Process.argc, Process.unsafeArgv) +NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) diff --git a/test/MogenSwiftTest/MogenSwiftTestTests/Info.plist b/test/MogenSwiftTest/MogenSwiftTestTests/Info.plist index 65113671..6d32c15c 100644 --- a/test/MogenSwiftTest/MogenSwiftTestTests/Info.plist +++ b/test/MogenSwiftTest/MogenSwiftTestTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.rentzsch.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/test/MogenSwiftTest/MogenSwiftTestTests/MogenSwiftTestTests.swift b/test/MogenSwiftTest/MogenSwiftTestTests/MogenSwiftTestTests.swift index ca7b0670..1196f5e7 100644 --- a/test/MogenSwiftTest/MogenSwiftTestTests/MogenSwiftTestTests.swift +++ b/test/MogenSwiftTest/MogenSwiftTestTests/MogenSwiftTestTests.swift @@ -1,11 +1,11 @@ import Cocoa import XCTest -import MogenSwiftTest +@testable import MogenSwiftTest class MogenSwiftTestTests: XCTestCase { func newMoc() -> (NSManagedObjectContext) { - let momURL : NSURL = NSBundle.mainBundle().URLForResource("MogenSwiftTest", withExtension: "momd")! - let mom : NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: momURL)! + let momURL : URL = Bundle.main.url(forResource: "MogenSwiftTest", withExtension: "momd")! + let mom : NSManagedObjectModel = NSManagedObjectModel(contentsOf: momURL)! let psc : NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: mom); let ps : NSPersistentStore = psc.addPersistentStoreWithType( NSInMemoryStoreType, @@ -86,7 +86,7 @@ class MogenSwiftTestTests: XCTestCase { } extension NSEntityDescription { - class func entityForName_workaround(entityName: String!, inManagedObjectContext context: NSManagedObjectContext!) -> NSEntityDescription! { + class func entityForName_workaround(_ entityName: String!, inManagedObjectContext context: NSManagedObjectContext!) -> NSEntityDescription! { let entities = context.persistentStoreCoordinator!.managedObjectModel.entitiesByName; let keys = Array(entities.keys) var result : NSEntityDescription? @@ -97,4 +97,4 @@ extension NSEntityDescription { } return result } -} \ No newline at end of file +} diff --git a/test/swift/Gender.swift b/test/swift/Gender.swift index 6f2b4443..d054ea17 100644 --- a/test/swift/Gender.swift +++ b/test/swift/Gender.swift @@ -1,6 +1,6 @@ // Mostly stolen from http://abcnewsgocom/blogs/headlines/2014/02/heres-a-list-of-58-gender-options-for-facebook-users/ -enum Gender: Int32 { +enum Gender: Int { case Undefined = 0, Female, Male, @@ -44,7 +44,7 @@ enum Gender: Int32 { TranssexualPerson func toString() -> String { - return String(self) + return String(describing: self) } } diff --git a/test/swift/MyBaseClass.swift b/test/swift/MyBaseClass.swift index 23231198..8ddf55c5 100644 --- a/test/swift/MyBaseClass.swift +++ b/test/swift/MyBaseClass.swift @@ -1,6 +1,6 @@ import Foundation import CoreData -public class MyBaseClass: NSManagedObject { +open class MyBaseClass: NSManagedObject { var ivar: Double = -1.0 } diff --git a/test/swift/main.swift b/test/swift/main.swift index a74746c4..75d6e568 100644 --- a/test/swift/main.swift +++ b/test/swift/main.swift @@ -5,35 +5,35 @@ struct CoreDataStore { let moc: NSManagedObjectContext init() { - let modelURL = NSURL(fileURLWithPath: "test.mom") - let model = NSManagedObjectModel(contentsOfURL: modelURL) + let modelURL = URL(fileURLWithPath: "test.mom") + let model = NSManagedObjectModel(contentsOf: modelURL as URL) let psc = NSPersistentStoreCoordinator(managedObjectModel: model!) do { - try psc.addPersistentStoreWithType(NSInMemoryStoreType, configuration: nil, URL: nil, options: nil) + let _ = try psc.addPersistentStore(ofType: NSInMemoryStoreType, configurationName: nil, at: nil, options: nil) } catch { assertionFailure("Can't bring up PSC") } - moc = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) + moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) moc.persistentStoreCoordinator = psc } } let dataStore = CoreDataStore() let moc = dataStore.moc - +// let homer = ParentMO(managedObjectContext: moc)! homer.humanName = "homer" homer.parentName = homer.humanName homer.ivar = 1.0 -homer.gender = NSNumber(int: Gender.Male.rawValue) +homer.gender = NSNumber(value: Gender.Male.rawValue) let marge = ParentMO(managedObjectContext: moc)! marge.humanName = "marge" marge.parentName = marge.humanName marge.ivar = 1.0 -marge.gender = NSNumber(int: Gender.Female.rawValue) +marge.gender = NSNumber(value: Gender.Female.rawValue) assert(homer.children.count == 0) assert(marge.children.count == 0)