From 940d95a3b967444918764c1d04063667f562fa28 Mon Sep 17 00:00:00 2001 From: Jangles Date: Fri, 13 Oct 2017 09:38:48 -0500 Subject: [PATCH] Swift 4 compatibility --- netfox.podspec | 2 +- netfox.xcodeproj/project.pbxproj | 26 ++++++++++++++----- .../xcschemes/netfox_ios.xcscheme | 4 ++- .../xcschemes/netfox_osx.xcscheme | 4 ++- netfox/Core/NFX.swift | 8 +++--- netfox/Core/NFXAssets.swift | 2 +- netfox/Core/NFXGenericController.swift | 8 +++--- netfox/Core/NFXListController.swift | 2 +- netfox/Core/NFXWindowController.swift | 2 +- netfox/OSX/NFXListController_OSX.swift | 12 ++++----- netfox/OSX/NFXSettingsController_OSX.swift | 16 ++++++------ netfox/iOS/NFXDetailsController_iOS.swift | 14 +++++----- netfox/iOS/NFXListController_iOS.swift | 6 ++--- netfox/iOS/NFXSettingsController_iOS.swift | 8 +++--- 14 files changed, 65 insertions(+), 49 deletions(-) diff --git a/netfox.podspec b/netfox.podspec index 11a4b0a1..a5a3694e 100644 --- a/netfox.podspec +++ b/netfox.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "netfox" - s.version = "1.9" + s.version = "1.10" s.summary = "A lightweight, one line setup, iOS/OSX network debugging library!" s.description = <<-DESC diff --git a/netfox.xcodeproj/project.pbxproj b/netfox.xcodeproj/project.pbxproj index ad33b47b..f15287ba 100644 --- a/netfox.xcodeproj/project.pbxproj +++ b/netfox.xcodeproj/project.pbxproj @@ -262,16 +262,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = kasketis; TargetAttributes = { B3BC020E1C09CDA000C17F3A = { CreatedOnToolsVersion = 7.1.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; }; E20FD2E81C6912D400DCFF61 = { CreatedOnToolsVersion = 7.2.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 0900; }; }; }; @@ -387,14 +387,20 @@ 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; @@ -437,14 +443,20 @@ 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; @@ -489,7 +501,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -508,7 +520,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.kasketis.netfox-iOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -532,7 +544,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -555,7 +567,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/netfox.xcodeproj/xcshareddata/xcschemes/netfox_ios.xcscheme b/netfox.xcodeproj/xcshareddata/xcschemes/netfox_ios.xcscheme index 2dfc3ba3..6bd7d213 100644 --- a/netfox.xcodeproj/xcshareddata/xcschemes/netfox_ios.xcscheme +++ b/netfox.xcodeproj/xcshareddata/xcschemes/netfox_ios.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/netfox.xcodeproj/xcshareddata/xcschemes/netfox_osx.xcscheme b/netfox.xcodeproj/xcshareddata/xcschemes/netfox_osx.xcscheme index 62342c1c..90ad5e4f 100644 --- a/netfox.xcodeproj/xcshareddata/xcschemes/netfox_osx.xcscheme +++ b/netfox.xcodeproj/xcshareddata/xcschemes/netfox_osx.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index 773ec11c..24f22a10 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -115,7 +115,7 @@ open class NFX: NSObject URLProtocol.unregisterClass(NFXProtocol.self) } - func motionDetected() + @objc func motionDetected() { guard self.started else { return } toggleNFX() @@ -246,7 +246,7 @@ extension NFX { navigationController!.navigationBar.isTranslucent = false navigationController!.navigationBar.tintColor = UIColor.NFXOrangeColor() navigationController!.navigationBar.barTintColor = UIColor.NFXStarkWhiteColor() - navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.NFXOrangeColor()] + navigationController!.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.NFXOrangeColor()] presentingViewController?.present(navigationController!, animated: true, completion: nil) } @@ -280,7 +280,7 @@ extension NFX { self.nfxMenuItem.target = self self.nfxMenuItem.action = #selector(NFX.motionDetected) self.nfxMenuItem.keyEquivalent = "n" - self.nfxMenuItem.keyEquivalentModifierMask = NSEventModifierFlags(rawValue: UInt(Int(NSEventModifierFlags.command.rawValue | NSEventModifierFlags.shift.rawValue))) + self.nfxMenuItem.keyEquivalentModifierMask = NSEvent.ModifierFlags(rawValue: UInt(Int(NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue))) } public func addNetfoxToMainMenu() { @@ -298,7 +298,7 @@ extension NFX { public func showNFXFollowingPlatform() { if self.windowController == nil { - self.windowController = NFXWindowController(windowNibName: "NetfoxWindow") + self.windowController = NFXWindowController(windowNibName: NSNib.Name(rawValue: "NetfoxWindow")) } self.windowController?.showWindow(nil) } diff --git a/netfox/Core/NFXAssets.swift b/netfox/Core/NFXAssets.swift index caf7fc38..cff3403e 100644 --- a/netfox/Core/NFXAssets.swift +++ b/netfox/Core/NFXAssets.swift @@ -18,7 +18,7 @@ class NFXAssets { class func getImage(_ image: NFXAssetName) -> Data { - var base64Image: String = { + let base64Image: String = { switch image { case .settings: return getSettingsImageBase64() case .close: return getCloseImageBase64() diff --git a/netfox/Core/NFXGenericController.swift b/netfox/Core/NFXGenericController.swift index 55aec64f..46421a06 100755 --- a/netfox/Core/NFXGenericController.swift +++ b/netfox/Core/NFXGenericController.swift @@ -44,22 +44,22 @@ class NFXGenericController: NFXViewController let matchesBodyHeaders = regexBodyHeaders.matches(in: string, options: NSRegularExpression.MatchingOptions.withoutAnchoringBounds, range: NSMakeRange(0, l)) as Array for match in matchesBodyHeaders { - tempMutableString.addAttribute(NSFontAttributeName, value: NFXFont.NFXFontBold(size: 14), range: match.range) - tempMutableString.addAttribute(NSForegroundColorAttributeName, value: NFXColor.NFXOrangeColor(), range: match.range) + tempMutableString.addAttribute(NSAttributedStringKey.font, value: NFXFont.NFXFontBold(size: 14), range: match.range) + tempMutableString.addAttribute(NSAttributedStringKey.foregroundColor, value: NFXColor.NFXOrangeColor(), range: match.range) } let regexKeys = try! NSRegularExpression(pattern: "\\[.+?\\]", options: NSRegularExpression.Options.caseInsensitive) let matchesKeys = regexKeys.matches(in: string, options: NSRegularExpression.MatchingOptions.withoutAnchoringBounds, range: NSMakeRange(0, l)) as Array for match in matchesKeys { - tempMutableString.addAttribute(NSForegroundColorAttributeName, value: NFXColor.NFXBlackColor(), range: match.range) + tempMutableString.addAttribute(NSAttributedStringKey.foregroundColor, value: NFXColor.NFXBlackColor(), range: match.range) } return tempMutableString } - func reloadData() + @objc func reloadData() { } } diff --git a/netfox/Core/NFXListController.swift b/netfox/Core/NFXListController.swift index f99bf36a..268d1e81 100644 --- a/netfox/Core/NFXListController.swift +++ b/netfox/Core/NFXListController.swift @@ -29,7 +29,7 @@ class NFXListController: NFXGenericController { self.filteredTableData = array as! [NFXHTTPModel] } - func reloadTableViewData() + @objc func reloadTableViewData() { } diff --git a/netfox/Core/NFXWindowController.swift b/netfox/Core/NFXWindowController.swift index 3a94ce44..aa4788e4 100644 --- a/netfox/Core/NFXWindowController.swift +++ b/netfox/Core/NFXWindowController.swift @@ -63,7 +63,7 @@ class NFXWindowController: NSWindowController, NSWindowDelegate, NFXWindowContro // MARK: NSWindowDelegate - func windowWillClose(notification: NSNotification) { + func windowWillClose(_ notification: Notification) { if let window = notification.object as? NSWindow , window == self.window { NFX.sharedInstance().windowDidClose() } diff --git a/netfox/OSX/NFXListController_OSX.swift b/netfox/OSX/NFXListController_OSX.swift index f70a3d4b..8ca18088 100644 --- a/netfox/OSX/NFXListController_OSX.swift +++ b/netfox/OSX/NFXListController_OSX.swift @@ -24,7 +24,7 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView // MARK: View Life Cycle override func awakeFromNib() { - tableView.register(NSNib(nibNamed: cellIdentifier, bundle: nil), forIdentifier: cellIdentifier) + tableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: nil), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) searchField.delegate = self NotificationCenter.default.addObserver(self, selector: #selector(NFXListController.reloadTableViewData), name: NSNotification.Name(rawValue: "NFXReloadData"), object: nil) @@ -40,7 +40,7 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView } } - func deactivateSearchController() + @objc func deactivateSearchController() { self.isSearchControllerActive = false } @@ -72,9 +72,9 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView } } - func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { + func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { - guard let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NFXListCell_OSX else { + guard let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: nil) as? NFXListCell_OSX else { return nil } @@ -95,11 +95,11 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView // MARK: NSTableViewDelegate - func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat { + func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { return 58 } - func tableViewSelectionDidChange(notification: NSNotification) { + func tableViewSelectionDidChange(_ notification: Notification) { guard tableView.selectedRow >= 0 else { return } diff --git a/netfox/OSX/NFXSettingsController_OSX.swift b/netfox/OSX/NFXSettingsController_OSX.swift index 4009c458..f2926db2 100644 --- a/netfox/OSX/NFXSettingsController_OSX.swift +++ b/netfox/OSX/NFXSettingsController_OSX.swift @@ -25,7 +25,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N nfxVersionLabel.stringValue = nfxVersionString nfxURLButton.title = nfxURL - responseTypesTableView.register(NSNib(nibNamed: cellIdentifier, bundle: nil), forIdentifier: cellIdentifier) + responseTypesTableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: nil), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) reloadTableData() } @@ -38,7 +38,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N // MARK: Actions @IBAction func loggingButtonClicked(sender: NSButton) { - if sender.state == NSOnState { + if sender.state == .on { NFX.sharedInstance().enable() } else { NFX.sharedInstance().disable() @@ -51,7 +51,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N } @IBAction func nfxURLButtonClicked(sender: NSButton) { - NSWorkspace.shared().open(NSURL(string: nfxURL)! as URL) + NSWorkspace.shared.open(NSURL(string: nfxURL)! as URL) } @IBAction func toggleResponseTypeClicked(sender: NSButton) { @@ -72,21 +72,21 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N return tableData.count } - func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { - guard let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NFXResponseTypeCell_OSX else { + func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { + guard let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: nil) as? NFXResponseTypeCell_OSX else { return nil } let shortType = tableData[row] cell.typeLabel.stringValue = shortType.rawValue - cell.activeCheckbox.state = filters[row] ? NSOnState : NSOffState + cell.activeCheckbox.state = filters[row] ? .on : .off cell.activeCheckbox.tag = row cell.activeCheckbox.target = self - cell.activeCheckbox.action = "toggleResponseTypeClicked:" + cell.activeCheckbox.action = #selector(toggleResponseTypeClicked(sender:)) return cell } - func tableView(tableView: NSTableView, shouldSelectRow: Int) -> Bool { + func tableView(_ tableView: NSTableView, shouldSelectRow: Int) -> Bool { return false } diff --git a/netfox/iOS/NFXDetailsController_iOS.swift b/netfox/iOS/NFXDetailsController_iOS.swift index 19be353c..d4bd33af 100755 --- a/netfox/iOS/NFXDetailsController_iOS.swift +++ b/netfox/iOS/NFXDetailsController_iOS.swift @@ -168,7 +168,7 @@ class NFXDetailsController_iOS: NFXDetailsController, MFMailComposeViewControlle return scrollView } - func actionButtonPressed(_ sender: UIBarButtonItem) + @objc func actionButtonPressed(_ sender: UIBarButtonItem) { let actionSheetController: UIAlertController = UIAlertController(title: "Share", message: nil, preferredStyle: .actionSheet) @@ -189,22 +189,22 @@ class NFXDetailsController_iOS: NFXDetailsController, MFMailComposeViewControlle self.present(actionSheetController, animated: true, completion: nil) } - func infoButtonPressed() + @objc func infoButtonPressed() { buttonPressed(self.infoButton) } - func requestButtonPressed() + @objc func requestButtonPressed() { buttonPressed(self.requestButton) } - func responseButtonPressed() + @objc func responseButtonPressed() { buttonPressed(self.responseButton) } - func handleSwipe(_ gesture: UISwipeGestureRecognizer) { + @objc func handleSwipe(_ gesture: UISwipeGestureRecognizer) { guard let currentButtonIdx = headerButtons.index(where: { $0.isSelected }) else { return } let numButtons = headerButtons.count @@ -244,12 +244,12 @@ class NFXDetailsController_iOS: NFXDetailsController, MFMailComposeViewControlle completion: nil) } - func responseBodyButtonPressed() + @objc func responseBodyButtonPressed() { bodyButtonPressed().bodyType = NFXBodyType.response } - func requestBodyButtonPressed() + @objc func requestBodyButtonPressed() { bodyButtonPressed().bodyType = NFXBodyType.request } diff --git a/netfox/iOS/NFXListController_iOS.swift b/netfox/iOS/NFXListController_iOS.swift index db8bd021..bc252066 100755 --- a/netfox/iOS/NFXListController_iOS.swift +++ b/netfox/iOS/NFXListController_iOS.swift @@ -82,14 +82,14 @@ class NFXListController_iOS: NFXListController, UITableViewDelegate, UITableView reloadTableViewData() } - func settingsButtonPressed() + @objc func settingsButtonPressed() { var settingsController: NFXSettingsController_iOS settingsController = NFXSettingsController_iOS() self.navigationController?.pushViewController(settingsController, animated: true) } - func closeButtonPressed() + @objc func closeButtonPressed() { NFX.sharedInstance().hide() } @@ -102,7 +102,7 @@ class NFXListController_iOS: NFXListController, UITableViewDelegate, UITableView reloadTableViewData() } - func deactivateSearchController() + @objc func deactivateSearchController() { self.searchController.isActive = false } diff --git a/netfox/iOS/NFXSettingsController_iOS.swift b/netfox/iOS/NFXSettingsController_iOS.swift index 9dc18afc..65bc4c41 100644 --- a/netfox/iOS/NFXSettingsController_iOS.swift +++ b/netfox/iOS/NFXSettingsController_iOS.swift @@ -73,19 +73,19 @@ class NFXSettingsController_iOS: NFXSettingsController, UITableViewDelegate, UIT NFX.sharedInstance().cacheFilters(self.filters) } - func nfxURLButtonPressed() + @objc func nfxURLButtonPressed() { UIApplication.shared.openURL(URL(string: nfxURL)!) } - func infoButtonPressed() + @objc func infoButtonPressed() { var infoController: NFXInfoController_iOS infoController = NFXInfoController_iOS() self.navigationController?.pushViewController(infoController, animated: true) } - func statisticsButtonPressed() + @objc func statisticsButtonPressed() { var statisticsController: NFXStatisticsController_iOS statisticsController = NFXStatisticsController_iOS() @@ -265,7 +265,7 @@ class NFXSettingsController_iOS: NFXSettingsController, UITableViewDelegate, UIT } - func nfxEnabledSwitchValueChanged(_ sender: UISwitch) + @objc func nfxEnabledSwitchValueChanged(_ sender: UISwitch) { if sender.isOn { NFX.sharedInstance().enable()