From 44ae1f0afcec950cc18c5942e0180d45771393dc Mon Sep 17 00:00:00 2001 From: Janusz Chudzynski Date: Tue, 17 Nov 2015 08:45:54 -0600 Subject: [PATCH] Updated to Swift 2.1 --- JMCMarchingAnts.xcodeproj/project.pbxproj | 25 +--- .../xcschemes/JMCMarchingAnts.xcscheme | 13 +- JMCMarchingAnts/AppDelegate.swift | 65 +------- JMCMarchingAnts/Base.lproj/Main.storyboard | 5 +- JMCMarchingAnts/Info.plist | 2 +- JMCMarchingAnts/JMCMarchingAnts.swift | 139 +++++++++--------- .../.xccurrentversion | 5 +- JMCMarchingAntsTests/Info.plist | 2 +- 8 files changed, 90 insertions(+), 166 deletions(-) diff --git a/JMCMarchingAnts.xcodeproj/project.pbxproj b/JMCMarchingAnts.xcodeproj/project.pbxproj index aba7df2..23c9bb7 100644 --- a/JMCMarchingAnts.xcodeproj/project.pbxproj +++ b/JMCMarchingAnts.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 4026614C1BE7F52400BF39D6 /* 038420-glossy-black-icon-transport-travel-transportation-car9-sc44.png in Resources */ = {isa = PBXBuildFile; fileRef = 4026614B1BE7F52400BF39D6 /* 038420-glossy-black-icon-transport-travel-transportation-car9-sc44.png */; }; 4026614D1BE7F52400BF39D6 /* 038420-glossy-black-icon-transport-travel-transportation-car9-sc44.png in Resources */ = {isa = PBXBuildFile; fileRef = 4026614B1BE7F52400BF39D6 /* 038420-glossy-black-icon-transport-travel-transportation-car9-sc44.png */; }; 4049CD7E1BC2D43F00F1E353 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4049CD7D1BC2D43F00F1E353 /* AppDelegate.swift */; }; - 4049CD811BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 4049CD7F1BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodeld */; }; 4049CD831BC2D43F00F1E353 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4049CD821BC2D43F00F1E353 /* ViewController.swift */; }; 4049CD861BC2D43F00F1E353 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4049CD841BC2D43F00F1E353 /* Main.storyboard */; }; 4049CD881BC2D43F00F1E353 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4049CD871BC2D43F00F1E353 /* Images.xcassets */; }; @@ -35,7 +34,6 @@ 4049CD781BC2D43F00F1E353 /* JMCMarchingAnts.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JMCMarchingAnts.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4049CD7C1BC2D43F00F1E353 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4049CD7D1BC2D43F00F1E353 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 4049CD801BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = JMCMarchingAnts.xcdatamodel; sourceTree = ""; }; 4049CD821BC2D43F00F1E353 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 4049CD851BC2D43F00F1E353 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 4049CD871BC2D43F00F1E353 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -91,7 +89,6 @@ 4049CD841BC2D43F00F1E353 /* Main.storyboard */, 4049CD871BC2D43F00F1E353 /* Images.xcassets */, 4049CD891BC2D43F00F1E353 /* LaunchScreen.xib */, - 4049CD7F1BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodeld */, 4026614B1BE7F52400BF39D6 /* 038420-glossy-black-icon-transport-travel-transportation-car9-sc44.png */, 4049CD7B1BC2D43F00F1E353 /* Supporting Files */, ); @@ -167,8 +164,9 @@ 4049CD701BC2D43F00F1E353 /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0710; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0640; + LastUpgradeCheck = 0710; ORGANIZATIONNAME = "Janusz Chudzynski"; TargetAttributes = { 4049CD771BC2D43F00F1E353 = { @@ -229,7 +227,6 @@ 4049CD831BC2D43F00F1E353 /* ViewController.swift in Sources */, 4049CDA41BC2D54B00F1E353 /* JMCMarchingAnts.swift in Sources */, 4049CD7E1BC2D43F00F1E353 /* AppDelegate.swift in Sources */, - 4049CD811BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodeld in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -293,6 +290,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -360,6 +358,7 @@ CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = JMCMarchingAnts/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -373,6 +372,7 @@ CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = JMCMarchingAnts/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; }; @@ -393,6 +393,7 @@ ); INFOPLIST_FILE = JMCMarchingAntsTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -411,6 +412,7 @@ ); INFOPLIST_FILE = JMCMarchingAntsTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JMCMarchingAnts.app/JMCMarchingAnts"; @@ -448,19 +450,6 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ - -/* Begin XCVersionGroup section */ - 4049CD7F1BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodeld */ = { - isa = XCVersionGroup; - children = ( - 4049CD801BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodel */, - ); - currentVersion = 4049CD801BC2D43F00F1E353 /* JMCMarchingAnts.xcdatamodel */; - path = JMCMarchingAnts.xcdatamodeld; - sourceTree = ""; - versionGroupType = wrapper.xcdatamodel; - }; -/* End XCVersionGroup section */ }; rootObject = 4049CD701BC2D43F00F1E353 /* Project object */; } diff --git a/JMCMarchingAnts.xcodeproj/xcuserdata/jchudzynski.xcuserdatad/xcschemes/JMCMarchingAnts.xcscheme b/JMCMarchingAnts.xcodeproj/xcuserdata/jchudzynski.xcuserdatad/xcschemes/JMCMarchingAnts.xcscheme index 65bbdac..cc3b4fe 100644 --- a/JMCMarchingAnts.xcodeproj/xcuserdata/jchudzynski.xcuserdatad/xcschemes/JMCMarchingAnts.xcscheme +++ b/JMCMarchingAnts.xcodeproj/xcuserdata/jchudzynski.xcuserdatad/xcschemes/JMCMarchingAnts.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -62,15 +62,18 @@ ReferencedContainer = "container:JMCMarchingAnts.xcodeproj"> + + @@ -86,10 +89,10 @@ diff --git a/JMCMarchingAnts/AppDelegate.swift b/JMCMarchingAnts/AppDelegate.swift index c3a70ae..56eb7dc 100644 --- a/JMCMarchingAnts/AppDelegate.swift +++ b/JMCMarchingAnts/AppDelegate.swift @@ -41,71 +41,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Saves changes in the application's managed object context before the application terminates. - self.saveContext() + } - // MARK: - Core Data stack - - lazy var applicationDocumentsDirectory: NSURL = { - // The directory the application uses to store the Core Data store file. This code uses a directory named "com.jmc.quiz.JMCMarchingAnts" in the application's documents Application Support directory. - let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) - return urls[urls.count-1] as! NSURL - }() - - 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 = NSBundle.mainBundle().URLForResource("JMCMarchingAnts", withExtension: "momd")! - return NSManagedObjectModel(contentsOfURL: modelURL)! - }() - - lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = { - // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. - // Create the coordinator and store - var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) - let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("JMCMarchingAnts.sqlite") - var error: NSError? = nil - var failureReason = "There was an error creating or loading the application's saved data." - if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil { - coordinator = nil - // Report any error we got. - var dict = [String: AnyObject]() - dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" - dict[NSLocalizedFailureReasonErrorKey] = failureReason - dict[NSUnderlyingErrorKey] = error - error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) - // Replace this with code to handle the error appropriately. - // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - NSLog("Unresolved error \(error), \(error!.userInfo)") - abort() - } - - 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 { - return nil - } - var managedObjectContext = NSManagedObjectContext() - managedObjectContext.persistentStoreCoordinator = coordinator - return managedObjectContext - }() - - // MARK: - Core Data Saving support - - func saveContext () { - if let moc = self.managedObjectContext { - var error: NSError? = nil - if moc.hasChanges && !moc.save(&error) { - // Replace this implementation with code to handle the error appropriately. - // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - NSLog("Unresolved error \(error), \(error!.userInfo)") - abort() - } - } - } + } diff --git a/JMCMarchingAnts/Base.lproj/Main.storyboard b/JMCMarchingAnts/Base.lproj/Main.storyboard index 655a0d0..39b2f27 100644 --- a/JMCMarchingAnts/Base.lproj/Main.storyboard +++ b/JMCMarchingAnts/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + diff --git a/JMCMarchingAnts/Info.plist b/JMCMarchingAnts/Info.plist index 69a2950..6905cc6 100644 --- a/JMCMarchingAnts/Info.plist +++ b/JMCMarchingAnts/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/JMCMarchingAnts/JMCMarchingAnts.swift b/JMCMarchingAnts/JMCMarchingAnts.swift index db73ea9..86c3979 100644 --- a/JMCMarchingAnts/JMCMarchingAnts.swift +++ b/JMCMarchingAnts/JMCMarchingAnts.swift @@ -48,10 +48,9 @@ extension UIImage{ /** Helper function for saving image to png binary */ func saveToPNG( filename:String){ - let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String + let documentsPath:NSString = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] let destinationPath = documentsPath.stringByAppendingPathComponent(filename) - println(destinationPath) - UIImagePNGRepresentation(self).writeToFile(destinationPath, atomically: true) + UIImagePNGRepresentation(self)!.writeToFile(destinationPath, atomically: true) //UIImageJPEGRepresentation(image,1.0).writeToFile(destinationPath, atomically: true) @@ -65,31 +64,31 @@ extension UIImage{ let context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor) CGContextFillRect(context, CGRectMake(0,0,frame.size.width,frame.size.height)) - foregroundImage.drawInRect(CGRectMake(realFrame.origin.x,realFrame.origin.y,realFrame.size.width,realFrame.size.height), blendMode: kCGBlendModeDestinationOut, alpha: 1.0) + foregroundImage.drawInRect(CGRectMake(realFrame.origin.x,realFrame.origin.y,realFrame.size.width,realFrame.size.height), blendMode:CGBlendMode.DestinationOut, alpha: 1.0) let cgimage = CGBitmapContextCreateImage(context); - let image = UIImage(CGImage: cgimage) + let image = UIImage(CGImage: cgimage!) UIGraphicsEndImageContext(); - return image!; + return image; } //Creates a ARGB Image func argbImage()->UIImage? { - let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() - let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.rawValue) + let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()! + let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue) let bytesPerRow = 4 * self.size.width - let context = CGBitmapContextCreate(nil, Int(self.size.width), Int(self.size.height), 8, Int(bytesPerRow), colorSpace, bitmapInfo) + let context = CGBitmapContextCreate(nil, Int(self.size.width), Int(self.size.height), 8, Int(bytesPerRow), colorSpace, bitmapInfo.rawValue) CGContextDrawImage(context, CGRectMake(0, 0, CGFloat(self.size.width), CGFloat(self.size.height)), self.CGImage) let cgimage = CGBitmapContextCreateImage(context) - let img = UIImage(CGImage: cgimage) + let img = UIImage(CGImage: cgimage!) return img } //Image from raw bitmap internal func imageFromARGB32Bitmap(pixels:[PixelData], width:Int, height:Int)->UIImage? { let rgbColorSpace = CGColorSpaceCreateDeviceRGB() - let bitmapInfo:CGBitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.rawValue) + let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue) let bitsPerComponent:Int = 8 let bitsPerPixel:Int = 32 @@ -100,7 +99,6 @@ extension UIImage{ NSData(bytes: &data, length: data.count * sizeof(PixelData)) ) - // let redPixel = PixelData(a: 255, r: 192, g: 0, b: 0) let cgim = CGImageCreate( width, @@ -113,24 +111,24 @@ extension UIImage{ providerRef, nil, true, - kCGRenderingIntentDefault + CGColorRenderingIntent.RenderingIntentDefault ) - return UIImage(CGImage: cgim) + return UIImage(CGImage: cgim!) } //Finds edges in the image (should be black and transparent colors only) func findEdges()->UIImage{ - let cgImage:CGImageRef = self.argbImage()!.CGImage + let cgImage:CGImageRef = self.argbImage()!.CGImage! //// - var pixelData = CGDataProviderCopyData(CGImageGetDataProvider(cgImage)) + let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(cgImage)) //var data = CFDataGetMutableBytePtr - var mdata: UnsafePointer = CFDataGetBytePtr(pixelData) - var data = UnsafeMutablePointer(mdata) + let mdata: UnsafePointer = CFDataGetBytePtr(pixelData) + let data = UnsafeMutablePointer(mdata) let height = CGImageGetHeight(cgImage) let width = CGImageGetWidth(cgImage) - var start = CACurrentMediaTime() + let start = CACurrentMediaTime() //create an empty buffer let emptyPixel = PixelData(a: 0, r: 0, g: 0, b: 0) @@ -143,10 +141,10 @@ extension UIImage{ for var y = 0; y < height-1; y++ { for var x = 0; x < width; x++ { //Current one - var currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 - var currentAlpha = CGFloat(data[currentPixelInfo+0]) / CGFloat(255.0) - var downPixelInfo: Int = ((Int(width) * Int(y+1)) + Int(x)) * 4 - var downAlpha = CGFloat(data[downPixelInfo+0]) / CGFloat(255.0) + let currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 + let currentAlpha = CGFloat(data[currentPixelInfo+0]) / CGFloat(255.0) + let downPixelInfo: Int = ((Int(width) * Int(y+1)) + Int(x)) * 4 + let downAlpha = CGFloat(data[downPixelInfo+0]) / CGFloat(255.0) if y == 0 && currentAlpha != 0{ // Top Edge booleanArray[currentPixelInfo/4] = true @@ -155,8 +153,8 @@ extension UIImage{ if y > 0 && y < height - 2{ //one up - var topPixelInfo: Int = ((Int(width) * Int(y - 1)) + Int(x )) * 4 - var topAlpha = CGFloat(data[topPixelInfo]) / CGFloat(255.0) + let topPixelInfo: Int = ((Int(width) * Int(y - 1)) + Int(x )) * 4 + let topAlpha = CGFloat(data[topPixelInfo]) / CGFloat(255.0) if downAlpha == 0 && currentAlpha != 0 {//edge booleanArray[currentPixelInfo/4] = true @@ -183,11 +181,11 @@ extension UIImage{ for var x = 0; x < width-1; x++ { //Current one - var currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 - var currentAlpha = CGFloat(data[currentPixelInfo]) / CGFloat(255.0) + let currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 + let currentAlpha = CGFloat(data[currentPixelInfo]) / CGFloat(255.0) //Next - var nextPixelInfo: Int = ((Int(width) * Int(y)) + Int(x + 1)) * 4 - var nextAlpha = CGFloat(data[nextPixelInfo]) / CGFloat(255.0) + let nextPixelInfo: Int = ((Int(width) * Int(y)) + Int(x + 1)) * 4 + let nextAlpha = CGFloat(data[nextPixelInfo]) / CGFloat(255.0) //check horizontally @@ -197,8 +195,8 @@ extension UIImage{ } if x > 0 && x < width - 2{ //One before - var previousPixelInfo: Int = ((Int(width) * Int(y)) + Int(x - 1)) * 4 - var previousAlpha = CGFloat(data[previousPixelInfo]) / CGFloat(255.0) + let previousPixelInfo: Int = ((Int(width) * Int(y)) + Int(x - 1)) * 4 + let previousAlpha = CGFloat(data[previousPixelInfo]) / CGFloat(255.0) if nextAlpha == 0 && currentAlpha != 0 {//Living on the edge booleanArray[currentPixelInfo/4] = true @@ -218,14 +216,13 @@ extension UIImage{ } - var stop = CACurrentMediaTime() + let stop = CACurrentMediaTime() let image = imageFromARGB32Bitmap(buffer, width: width, height: height) - println(stop - start) + print(stop - start) return image!; - //self.imageView.image = image } @@ -248,18 +245,16 @@ class JMCMarchingAnts: NSObject { //Gets a layer with selected edges and adds animation func getSelectionLayer(image:UIImage, imageView: UIView)->CAShapeLayer{ - var boundaryShapeLayer = CAShapeLayer() - let path1 = self.convertEdgesToPath(image.CGImage) - let boundingBox = CGPathGetBoundingBox(path1) - - UIGraphicsBeginImageContext(boundingBox.size) - let context = UIGraphicsGetCurrentContext() - - CGContextAddPath(context, path1) - CGContextStrokePath(context) - - let img = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() + let boundaryShapeLayer = CAShapeLayer() + let path1 = self.convertEdgesToPath(image.CGImage!) +// let boundingBox = CGPathGetBoundingBox(path1) +// UIGraphicsBeginImageContext(boundingBox.size) +// let context = UIGraphicsGetCurrentContext() +// +// CGContextAddPath(context, path1) +// CGContextStrokePath(context) +// +// UIGraphicsEndImageContext() @@ -289,16 +284,16 @@ class JMCMarchingAnts: NSObject { //Converst Edges of the image to path func convertEdgesToPath(image:CGImageRef)->CGMutablePathRef{ - var pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image)) + let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image)) data = CFDataGetBytePtr(pixelData) // data = UnsafeMutablePointer(mdata) let height = CGImageGetHeight(image) let width = CGImageGetWidth(image) - var start = CACurrentMediaTime() + _ = CACurrentMediaTime() - var path = CGPathCreateMutable() + let path = CGPathCreateMutable() CGPathAddRect(path, nil, CGRectMake(0, 0, CGFloat(width), CGFloat(height))) visitedArray = [Bool](count: Int(width * height), repeatedValue: false) @@ -308,14 +303,14 @@ class JMCMarchingAnts: NSObject { for var x = 0; x < width; x++ { //Current one - var currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 - var currentAlpha = CGFloat(data[currentPixelInfo+3]) / CGFloat(255.0) + let currentPixelInfo: Int = ((Int(width) * Int(y)) + Int(x)) * 4 + let currentAlpha = CGFloat(data[currentPixelInfo+3]) / CGFloat(255.0) - var downPixelInfo: Int = ((Int(width) * Int(y+1)) + Int(x)) * 4 - var downAlpha = CGFloat(data[downPixelInfo+3]) / CGFloat(255.0) + let downPixelInfo: Int = ((Int(width) * Int(y+1)) + Int(x)) * 4 + _ = CGFloat(data[downPixelInfo+3]) / CGFloat(255.0) var currentPoint = CGPointMake(CGFloat(x ), CGFloat(y)) - // println(currentPoint) + // print(currentPoint) if visitedArray[currentPixelInfo/4] == true {//if we didn't already check this point continue @@ -332,58 +327,58 @@ class JMCMarchingAnts: NSObject { while (adjacent){ - // println(currentPoint) + // print(currentPoint) if checkTopLeft(currentPoint, data: data, width: width, height: height) { - var tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y-1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y-1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkLeft(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkBottomLeft(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y+1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x-1), CGFloat(currentPoint.y+1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkBottom(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x), CGFloat(currentPoint.y+1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x), CGFloat(currentPoint.y+1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkBottomRight(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y+1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y+1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkRight(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkTopRight(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y-1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x+1), CGFloat(currentPoint.y-1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint } else if checkTop(currentPoint, data: data, width: width, height: height){ - var tempPoint = CGPointMake(CGFloat(currentPoint.x), CGFloat(currentPoint.y-1)) + let tempPoint = CGPointMake(CGFloat(currentPoint.x), CGFloat(currentPoint.y-1)) CGPathAddLineToPoint(path, nil, tempPoint.x, tempPoint.y) currentPoint = tempPoint @@ -405,7 +400,7 @@ class JMCMarchingAnts: NSObject { return false } - var index = ((Int(width) * Int(point.y-1)) + Int(point.x+1)) * 4 + let index = ((Int(width) * Int(point.y-1)) + Int(point.x+1)) * 4 return checkPoint(index) } @@ -415,7 +410,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y)) + Int(point.x+1)) * 4 + let index = ((Int(width) * Int(point.y)) + Int(point.x+1)) * 4 return checkPoint(index) } @@ -425,7 +420,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y+1)) + Int(point.x+1)) * 4 + let index = ((Int(width) * Int(point.y+1)) + Int(point.x+1)) * 4 return checkPoint(index) } @@ -436,7 +431,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y+1)) + Int(point.x)) * 4 + let index = ((Int(width) * Int(point.y+1)) + Int(point.x)) * 4 return checkPoint(index) } @@ -446,7 +441,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y+1)) + Int(point.x-1)) * 4 + let index = ((Int(width) * Int(point.y+1)) + Int(point.x-1)) * 4 return checkPoint(index) } @@ -456,7 +451,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y)) + Int(point.x-1)) * 4 + let index = ((Int(width) * Int(point.y)) + Int(point.x-1)) * 4 return checkPoint(index) } @@ -466,7 +461,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y-1)) + Int(point.x-1)) * 4 + let index = ((Int(width) * Int(point.y-1)) + Int(point.x-1)) * 4 return checkPoint(index) } @@ -476,7 +471,7 @@ class JMCMarchingAnts: NSObject { { return false } - var index = ((Int(width) * Int(point.y-1)) + Int(point.x)) * 4 + let index = ((Int(width) * Int(point.y-1)) + Int(point.x)) * 4 return checkPoint(index) } @@ -484,7 +479,7 @@ class JMCMarchingAnts: NSObject { func checkPoint(index:Int )->Bool{ //check if it is visible - var currentAlpha = CGFloat(data[index+3]) / CGFloat(255.0) + let currentAlpha = CGFloat(data[index+3]) / CGFloat(255.0) if visitedArray[index/4] == true{ //check if visited return false diff --git a/JMCMarchingAnts/JMCMarchingAnts.xcdatamodeld/.xccurrentversion b/JMCMarchingAnts/JMCMarchingAnts.xcdatamodeld/.xccurrentversion index 1535744..0c67376 100644 --- a/JMCMarchingAnts/JMCMarchingAnts.xcdatamodeld/.xccurrentversion +++ b/JMCMarchingAnts/JMCMarchingAnts.xcdatamodeld/.xccurrentversion @@ -1,8 +1,5 @@ - - _XCCurrentVersionName - JMCMarchingAnts.xcdatamodel - + diff --git a/JMCMarchingAntsTests/Info.plist b/JMCMarchingAntsTests/Info.plist index 6878206..ba72822 100644 --- a/JMCMarchingAntsTests/Info.plist +++ b/JMCMarchingAntsTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.jmc.quiz.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName