Skip to content

Commit

Permalink
Swift 4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Jangles committed Oct 13, 2017
1 parent e8389a7 commit 940d95a
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 49 deletions.
2 changes: 1 addition & 1 deletion netfox.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "netfox"
s.version = "1.9"
s.version = "1.10"

This comment has been minimized.

Copy link
@Abeansits

Abeansits Oct 14, 2017

Contributor

🍾 thank you!

This comment has been minimized.

Copy link
@Janglinator

Janglinator Oct 14, 2017

Contributor

@Abeansits No prob mate! Make sure to do a pull on 1.10.2, I missed a few key @objc's :)

s.summary = "A lightweight, one line setup, iOS/OSX network debugging library!"

s.description = <<-DESC
Expand Down
26 changes: 19 additions & 7 deletions netfox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -532,7 +544,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -555,7 +567,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
4 changes: 3 additions & 1 deletion netfox.xcodeproj/xcshareddata/xcschemes/netfox_ios.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 3 additions & 1 deletion netfox.xcodeproj/xcshareddata/xcschemes/netfox_osx.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
8 changes: 4 additions & 4 deletions netfox/Core/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ open class NFX: NSObject
URLProtocol.unregisterClass(NFXProtocol.self)
}

func motionDetected()
@objc func motionDetected()
{
guard self.started else { return }
toggleNFX()
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion netfox/Core/NFXAssets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions netfox/Core/NFXGenericController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ class NFXGenericController: NFXViewController
let matchesBodyHeaders = regexBodyHeaders.matches(in: string, options: NSRegularExpression.MatchingOptions.withoutAnchoringBounds, range: NSMakeRange(0, l)) as Array<NSTextCheckingResult>

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<NSTextCheckingResult>

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()
{
}
}
2 changes: 1 addition & 1 deletion netfox/Core/NFXListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NFXListController: NFXGenericController {
self.filteredTableData = array as! [NFXHTTPModel]
}

func reloadTableViewData()
@objc func reloadTableViewData()
{
}

Expand Down
2 changes: 1 addition & 1 deletion netfox/Core/NFXWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
12 changes: 6 additions & 6 deletions netfox/OSX/NFXListController_OSX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,7 +40,7 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView
}
}

func deactivateSearchController()
@objc func deactivateSearchController()
{
self.isSearchControllerActive = false
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions netfox/OSX/NFXSettingsController_OSX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
Expand All @@ -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) {
Expand All @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions netfox/iOS/NFXDetailsController_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 940d95a

Please sign in to comment.