diff --git a/Bitmapper.xcodeproj/project.pbxproj b/Bitmapper.xcodeproj/project.pbxproj index c2c0532..e9b2832 100644 --- a/Bitmapper.xcodeproj/project.pbxproj +++ b/Bitmapper.xcodeproj/project.pbxproj @@ -156,12 +156,12 @@ FA50382E1AA371DD0090A1F5 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0610; + LastUpgradeCheck = 1240; ORGANIZATIONNAME = "Balancing Rock"; TargetAttributes = { FA5038351AA371DD0090A1F5 = { CreatedOnToolsVersion = 6.1.1; - DevelopmentTeam = 7P4D6LHV5G; + ProvisioningStyle = Automatic; }; FA5038471AA371DD0090A1F5 = { CreatedOnToolsVersion = 6.1.1; @@ -171,7 +171,7 @@ }; buildConfigurationList = FA5038311AA371DD0090A1F5 /* Build configuration list for PBXProject "Bitmapper" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -252,24 +252,38 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + 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", @@ -294,17 +308,29 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -313,6 +339,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; @@ -322,6 +349,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -329,12 +357,17 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Bitmapper/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -342,12 +375,17 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Bitmapper/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -366,6 +404,7 @@ ); INFOPLIST_FILE = BitmapperTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Bitmapper.app/Contents/MacOS/Bitmapper"; }; @@ -382,6 +421,7 @@ ); INFOPLIST_FILE = BitmapperTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Bitmapper.app/Contents/MacOS/Bitmapper"; }; diff --git a/Bitmapper/Base.lproj/Main.storyboard b/Bitmapper/Base.lproj/Main.storyboard index 1314e21..5555197 100644 --- a/Bitmapper/Base.lproj/Main.storyboard +++ b/Bitmapper/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -92,12 +94,15 @@ - + + + + @@ -144,7 +149,7 @@ - - - + + + - - + + - - + + + - - - - - + @@ -215,7 +218,7 @@ - + @@ -226,7 +229,7 @@ diff --git a/Bitmapper/DropZoneView.swift b/Bitmapper/DropZoneView.swift index 1ef71e0..48b62bb 100644 --- a/Bitmapper/DropZoneView.swift +++ b/Bitmapper/DropZoneView.swift @@ -8,19 +8,19 @@ import Cocoa -@objc protocol DropZoneDelegate: NSObjectProtocol, NSDraggingDestination { +@objc protocol DropZoneDelegate: NSDraggingDestination { /// Redirect of the draggingEntered function (optional) - optional func draggingEntered(info: NSDraggingInfo) -> NSDragOperation + @objc optional func draggingEntered(info: NSDraggingInfo) -> NSDragOperation /// Redirect of the draggingUpdated function (optional) - optional func draggingUpdated(info: NSDraggingInfo) -> NSDragOperation + @objc optional func draggingUpdated(info: NSDraggingInfo) -> NSDragOperation /// Redirect of the draggingExited function (optional) - optional func draggingExited(info: NSDraggingInfo) + @objc optional func draggingExited(info: NSDraggingInfo) /// Redirect of the prepareForDragOperation (optional) - optional func prepareForDragOperation(info: NSDraggingInfo) -> Bool + @objc optional func prepareForDragOperation(info: NSDraggingInfo) -> Bool /// Redirect of the performDragOperations (required) func performDragOperation(info: NSDraggingInfo) -> Bool @@ -37,7 +37,7 @@ class DropZoneView: NSView { var acceptedFiles: [String] = [] /// The dragOperation that will de returned if an optoinal DropZoneDelegate function has not been implemented - var defaultDragOperation = NSDragOperation.Copy + var defaultDragOperation = NSDragOperation.copy //MARK: - Functions @@ -51,7 +51,7 @@ class DropZoneView: NSView { types.append("NSTypedFilenamesPboardType:\(ext)") } - registerForDraggedTypes([NSFilenamesPboardType]) + registerForDraggedTypes([NSPasteboard.PasteboardType.string]) acceptedFiles = extensions } @@ -59,16 +59,16 @@ class DropZoneView: NSView { /// Returns the file urls from the given DraggingInfo class func fileUrlsFromDraggingInfo(info: NSDraggingInfo) -> [NSURL]? { - let pboard = info.draggingPasteboard() + let pboard = info.draggingPasteboard - if (pboard.types! as NSArray).containsObject(NSURLPboardType) { + if (pboard.types! as NSArray).contains(NSPasteboard.PasteboardType.string) { - var urls = pboard.readObjectsForClasses([NSURL.self], options: nil) as? [NSURL] + let urls = pboard.readObjects(forClasses: [NSURL.self], options: nil) as? [NSURL] var realUrls = [NSURL]() for url in urls! { - realUrls.append(url.filePathURL!) // use filePathURL to avoid file:// file id's + realUrls.append(url.filePathURL! as NSURL) // use filePathURL to avoid file:// file id's } @@ -84,15 +84,15 @@ class DropZoneView: NSView { private func hasValidFiles(info: NSDraggingInfo) -> Bool { var hasValidFiles = false - let pboard = info.draggingPasteboard() + _ = info.draggingPasteboard - var urls = DropZoneView.fileUrlsFromDraggingInfo(info) + let urls = DropZoneView.fileUrlsFromDraggingInfo(info: info) if urls == nil { return false } for url in urls! { - if contains(acceptedFiles, url.pathExtension!) { hasValidFiles = true } - + if acceptedFiles.contains(url.pathExtension!) { hasValidFiles = true } + } return hasValidFiles @@ -102,16 +102,16 @@ class DropZoneView: NSView { //MARK: - Dragging functions - override func draggingEntered(sender: NSDraggingInfo) -> NSDragOperation { + override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation { - if dropDelegate != nil && dropDelegate!.respondsToSelector(Selector("draggingEntered:")) { + if dropDelegate != nil && dropDelegate!.responds(to: #selector(NSDraggingDestination.draggingEntered(_:))) { return dropDelegate!.draggingEntered!(sender) } else { - if !hasValidFiles(sender) { - return NSDragOperation.None + if !hasValidFiles(info: sender) { + return NSDragOperation.generic } else { return defaultDragOperation } @@ -120,16 +120,16 @@ class DropZoneView: NSView { } - override func draggingUpdated(sender: NSDraggingInfo) -> NSDragOperation { + override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { - if dropDelegate != nil && dropDelegate!.respondsToSelector(Selector("draggingUpdated:")) { + if dropDelegate != nil && dropDelegate!.responds(to: #selector(NSDraggingDestination.draggingUpdated(_:))) { return dropDelegate!.draggingUpdated!(sender) } else { - if !hasValidFiles(sender) { - return NSDragOperation.None + if !hasValidFiles(info: sender) { + return NSDragOperation.generic } else { return defaultDragOperation } @@ -138,9 +138,9 @@ class DropZoneView: NSView { } - override func draggingExited(sender: NSDraggingInfo?) { + override func draggingExited(_ sender: NSDraggingInfo?) { - if dropDelegate != nil && dropDelegate!.respondsToSelector(Selector("draggingExited:")) { + if dropDelegate != nil && dropDelegate!.responds(to: #selector(NSDraggingDestination.draggingExited(_:))) { dropDelegate!.draggingExited!(sender!) @@ -148,9 +148,9 @@ class DropZoneView: NSView { } - override func prepareForDragOperation(sender: NSDraggingInfo) -> Bool { + override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool { - if dropDelegate != nil && dropDelegate!.respondsToSelector(Selector("prepareForDragOperation:")) { + if dropDelegate != nil && dropDelegate!.responds(to: #selector(NSDraggingDestination.prepareForDragOperation(_:))) { return dropDelegate!.prepareForDragOperation!(sender) @@ -160,10 +160,10 @@ class DropZoneView: NSView { } - override func performDragOperation(sender: NSDraggingInfo) -> Bool { + override func performDragOperation(_ sender: NSDraggingInfo) -> Bool { - if let del = dropDelegate? { - return dropDelegate!.performDragOperation(sender) + if let del = dropDelegate { + return del.performDragOperation(info: sender) } return true diff --git a/Bitmapper/Info.plist b/Bitmapper/Info.plist index e11aca5..bbee6d1 100644 --- a/Bitmapper/Info.plist +++ b/Bitmapper/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Bitmapper/ViewController.swift b/Bitmapper/ViewController.swift index 02e1d00..8e4a827 100644 --- a/Bitmapper/ViewController.swift +++ b/Bitmapper/ViewController.swift @@ -23,8 +23,8 @@ class ViewController: NSViewController, DropZoneDelegate { super.viewDidLoad() // setup dropView - dropView.registerForFileExtensions(["bmp"]) - dropView.defaultDragOperation = .Copy + dropView.registerForFileExtensions(extensions: ["bmp"]) + dropView.defaultDragOperation = .copy dropView.dropDelegate = self } @@ -41,11 +41,11 @@ class ViewController: NSViewController, DropZoneDelegate { if url.pathExtension! == "bmp" { // change selectedImage - selectedImage = NSImage(contentsOfURL: url) + selectedImage = NSImage(contentsOf: url as URL) // UI imageView.image = selectedImage - dragHereLabel.hidden = true + dragHereLabel.isHidden = true // update window title view.window!.title = "Bitmap to C array: \(url.lastPathComponent!) (width: \(Int(selectedImage!.size.width)) height: \(Int(selectedImage!.size.height)))" @@ -55,19 +55,18 @@ class ViewController: NSViewController, DropZoneDelegate { } private func valueForColor(color: NSColor) -> Int { - // if it is dark, return 1, and if it is light, return 0 return color.whiteComponent < 0.5 ? 1 : 0 - +// return color.brightnessComponent < 0.5 ? 1 : 0 } func performDragOperation(info: NSDraggingInfo) -> Bool { - let urls = DropZoneView.fileUrlsFromDraggingInfo(info) + let urls = DropZoneView.fileUrlsFromDraggingInfo(info: info) if urls != nil && urls!.count > 0 { - getImageFromURL(urls![0]) + getImageFromURL(url: urls![0]) } @@ -80,7 +79,7 @@ class ViewController: NSViewController, DropZoneDelegate { if let img = selectedImage { // get neccesary data: bitmaprep & dimensions - let rep = NSBitmapImageRep(data: img.TIFFRepresentation!)! + let rep = NSBitmapImageRep(data: img.tiffRepresentation!)! let height = Int(img.size.height) let width = Int(img.size.width) @@ -103,18 +102,18 @@ class ViewController: NSViewController, DropZoneDelegate { // add 1 or 0 at correct position in currentValue let lsl = bitsPerItem - posInCurrentValue - 1 - let bit = valueForColor(rep.colorAtX(col, y: row)!) << lsl + let bit = valueForColor(color: rep.colorAt(x: col, y: row)!) << lsl currentValue += bit - posInCurrentValue++ + posInCurrentValue += 1 if posInCurrentValue == bitsPerItem { // add to output string as hexadecimal with at least two digits, it still looks messy with more than 8 bits per array item let valueString = String(currentValue, radix: 16) - output += countElements(valueString) == 1 && bitsPerItem > 4 ? "0x0\(valueString)" : "0x\(valueString)" - + output += valueString.count == 1 && bitsPerItem > 4 ? "0x0\(valueString)" : "0x\(valueString)" + // if it isn't the last object, add a comma if row != height-1 || col != width-1 { output += ", " } @@ -148,10 +147,10 @@ class ViewController: NSViewController, DropZoneDelegate { panel.allowsMultipleSelection = false panel.allowedFileTypes = ["bmp"] - panel.beginWithCompletionHandler( { (result) -> Void in - if result == NSFileHandlingPanelOKButton { + panel.begin( completionHandler: { (result) -> Void in + if result.rawValue == NSFileHandlingPanelOKButton { - self.getImageFromURL(panel.URL!) + self.getImageFromURL(url: panel.url! as NSURL) } }) @@ -161,9 +160,9 @@ class ViewController: NSViewController, DropZoneDelegate { @IBAction func copyOutput(sender: AnyObject) { // copy contents of textView to generalPasteBoard - let pasteBoard = NSPasteboard.generalPasteboard() - pasteBoard.declareTypes([NSStringPboardType], owner: nil) - pasteBoard.setString(textView.string!, forType: NSStringPboardType) + let pasteBoard = NSPasteboard.general + pasteBoard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil) + pasteBoard.setString(textView.string, forType: NSPasteboard.PasteboardType.string) } } diff --git a/BitmapperTests/Info.plist b/BitmapperTests/Info.plist index 34edf60..ba72822 100644 --- a/BitmapperTests/Info.plist +++ b/BitmapperTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - nl.balancingrock.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName