From ef57bc6e17cd5ec307e8118ea133034f640e22e1 Mon Sep 17 00:00:00 2001 From: Guy Pascarella Date: Thu, 7 Dec 2017 08:08:38 -0500 Subject: [PATCH] Updated for Swift 4 and Xcode 9 --- .gitignore | 3 +++ IP Menu.xcodeproj/project.pbxproj | 42 ++++++++++++++++++++++--------- IP Menu/AppDelegate.swift | 14 +++++------ IP Menu/Info.plist | 2 +- IP Menu/NetworkUtils.swift | 3 ++- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index eb948ee..599f7d3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ **/xcuserdata/* **/xcshareddata/* +release.sh +release.plist + diff --git a/IP Menu.xcodeproj/project.pbxproj b/IP Menu.xcodeproj/project.pbxproj index c34493b..3123572 100644 --- a/IP Menu.xcodeproj/project.pbxproj +++ b/IP Menu.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 48; objects = { /* Begin PBXBuildFile section */ @@ -160,21 +160,21 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0910; TargetAttributes = { FFF7133E1B975643001612E9 = { CreatedOnToolsVersion = 6.4; - LastSwiftMigration = 0820; + LastSwiftMigration = 0910; }; FFF7134E1B975643001612E9 = { CreatedOnToolsVersion = 6.4; - LastSwiftMigration = 0820; + LastSwiftMigration = 0910; TestTargetID = FFF7133E1B975643001612E9; }; }; }; buildConfigurationList = FFF7133A1B975643001612E9 /* Build configuration list for PBXProject "IP Menu" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 8.0"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -260,18 +260,24 @@ 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_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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + 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 = "-"; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -296,6 +302,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -307,18 +314,24 @@ 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_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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + 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 = "-"; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; @@ -335,6 +348,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -348,7 +362,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.disrvptor.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "IP Menu-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; USER_HEADER_SEARCH_PATHS = ""; }; name = Debug; @@ -364,8 +379,9 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.disrvptor.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "IP Menu-Bridging-Header.h"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; USER_HEADER_SEARCH_PATHS = ""; }; name = Release; @@ -387,7 +403,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.disrvptor.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IP Menu.app/Contents/MacOS/IP Menu"; }; name = Debug; @@ -405,7 +422,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.disrvptor.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IP Menu.app/Contents/MacOS/IP Menu"; }; name = Release; diff --git a/IP Menu/AppDelegate.swift b/IP Menu/AppDelegate.swift index d06a4ca..22299ef 100644 --- a/IP Menu/AppDelegate.swift +++ b/IP Menu/AppDelegate.swift @@ -29,7 +29,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { internal var defaultIF: String?; func applicationDidFinishLaunching(_ aNotification: Notification) { - statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength); + statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength); // TODO: Figure out ho to modify this for dev/test vs production ConsoleLog.setCurrentLevel(ConsoleLog.Level.Info); @@ -42,11 +42,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationWillTerminate(_ aNotification: Notification) { timer = nil; - NSStatusBar.system().removeStatusItem(statusItem!); + NSStatusBar.system.removeStatusItem(statusItem!); statusItem = nil; } - func updateIPAddress() { + @objc func updateIPAddress() { let _addresses = NetworkUtils.getIFAddresses(); // Disable this for now because it looks like it may be causing the OS to deadlock //var _defaultIF: String? = "en0"; @@ -83,13 +83,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { menu.addItem(NSMenuItem(title: "Refresh", action: #selector(AppDelegate.updateIPAddress), keyEquivalent: "")); let item:NSMenuItem = NSMenuItem(title: "Launch at startup", action: #selector(AppDelegate.toggleLaunchAtStartup), keyEquivalent: ""); - item.state = state; + item.state = NSControl.StateValue(rawValue: state); menu.addItem(item); menu.addItem(NSMenuItem(title: "About IP Menu", action: #selector(AppDelegate.about), keyEquivalent: "")); menu.addItem(NSMenuItem.separator()); //menu.addItem(NSMenuItem(title: "Quit IP Menu", action: #selector(NSInputServiceProvider.Quit), keyEquivalent: "q")); - menu.addItem(NSMenuItem(title: "Quit IP Menu", action: #selector(NSApplication.shared().terminate), keyEquivalent: "q")); + menu.addItem(NSMenuItem(title: "Quit IP Menu", action: #selector(NSApplication.shared.terminate), keyEquivalent: "q")); statusItem!.menu = menu; } @@ -166,7 +166,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true; } - func about() { + @objc func about() { let alert = NSAlert(); alert.messageText = "IP Menu v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String)"; alert.informativeText = "Developed by @disrvptor (https://github.com/disrvptor/IPMenu)"; @@ -212,7 +212,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { return (nil, nil) } - func toggleLaunchAtStartup() { + @objc func toggleLaunchAtStartup() { let itemReferences = itemReferencesInLoginItems() let shouldBeToggled = (itemReferences.existingReference == nil) let loginItemsRef = LSSharedFileListCreate( diff --git a/IP Menu/Info.plist b/IP Menu/Info.plist index 682df98..58b4a98 100644 --- a/IP Menu/Info.plist +++ b/IP Menu/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.1 + 1.2.2 CFBundleSignature ???? CFBundleVersion diff --git a/IP Menu/NetworkUtils.swift b/IP Menu/NetworkUtils.swift index 970fca8..008defb 100644 --- a/IP Menu/NetworkUtils.swift +++ b/IP Menu/NetworkUtils.swift @@ -83,7 +83,8 @@ class NetworkUtils { for line in lines! { //let line2 = line.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()); if let range = line.range(of: "interface: ") { - return line.substring(from: range.upperBound); + //return line.substring(from: range.upperBound); + return String(line[range.upperBound...]); } }