Skip to content

Commit

Permalink
Merge pull request #71 from Nonnus/swift4
Browse files Browse the repository at this point in the history
migrated to swift4, bumped version to 1.0.7
  • Loading branch information
Robert Gummesson committed Sep 18, 2017
2 parents feda2bd + f41f389 commit 75f0e19
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,3 +1,3 @@
language: objective-c
osx_image: xcode8.2
script: xcodebuild -project BuildTimeAnalyzer.xcodeproj -scheme BuildTimeAnalyzer build test
language: swift
osx_image: xcode9
script: xcodebuild -project BuildTimeAnalyzer.xcodeproj -scheme BuildTimeAnalyzer build test
26 changes: 19 additions & 7 deletions BuildTimeAnalyzer.xcodeproj/project.pbxproj
Expand Up @@ -246,16 +246,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Cane Media Ltd";
TargetAttributes = {
2AF8213F1D21D6B900D65186 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
2AF8214E1D21D6B900D65186 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
TestTargetID = 2AF8213F1D21D6B900D65186;
};
};
Expand Down Expand Up @@ -350,14 +350,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 @@ -397,14 +403,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 @@ -438,7 +450,7 @@
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -452,7 +464,7 @@
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -468,7 +480,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BuildTimeAnalyzer.app/Contents/MacOS/BuildTimeAnalyzer";
};
name = Debug;
Expand All @@ -484,7 +496,7 @@
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BuildTimeAnalyzer.app/Contents/MacOS/BuildTimeAnalyzer";
};
name = Release;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
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>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
10 changes: 5 additions & 5 deletions BuildTimeAnalyzer/AppDelegate.swift
Expand Up @@ -13,11 +13,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var alwaysInFrontMenuItem: NSMenuItem!

var viewController: ViewController? {
return NSApplication.shared().mainWindow?.contentViewController as? ViewController
return NSApplication.shared.mainWindow?.contentViewController as? ViewController
}

func applicationDidFinishLaunching(_ notification: Notification) {
alwaysInFrontMenuItem.state = UserSettings.windowShouldBeTopMost ? NSOnState : NSOffState
alwaysInFrontMenuItem.state = UserSettings.windowShouldBeTopMost ? .on : .off
}

func configureMenuItems(showBuildTimesMenuItem: Bool) {
Expand All @@ -42,14 +42,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBAction func visitGitHubPage(_ sender: AnyObject) {
let path = "https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode"
if let url = URL(string: path) {
NSWorkspace.shared().open(url)
NSWorkspace.shared.open(url)
}
}

@IBAction func toggleAlwaysInFront(_ sender: NSMenuItem) {
let alwaysInFront = sender.state == NSOffState
let alwaysInFront = sender.state == .off

sender.state = alwaysInFront ? NSOnState : NSOffState
sender.state = alwaysInFront ? .on : .off
UserSettings.windowShouldBeTopMost = alwaysInFront

viewController?.makeWindowTopMost(topMost: alwaysInFront)
Expand Down
16 changes: 8 additions & 8 deletions BuildTimeAnalyzer/CompileMeasure.swift
Expand Up @@ -32,13 +32,13 @@ struct CompileMeasure {
}

init?(time: Double, rawPath: String, code: String, references: Int) {
let untrimmedFilename = rawPath.characters.split(separator: "/").map(String.init).last
let untrimmedFilename = rawPath.split(separator: "/").map(String.init).last

guard let filepath = rawPath.characters.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.characters.split(separator: ":").map(String.init).first else { return nil }
guard let filepath = rawPath.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.split(separator: ":").map(String.init).first else { return nil }

let locationString = String(rawPath.substring(from: filepath.endIndex).characters.dropFirst())
let locations = locationString.characters.split(separator: ":").flatMap{ Int(String.init($0)) }
let locationString = String(rawPath[filepath.endIndex...].dropFirst())
let locations = locationString.split(separator: ":").flatMap{ Int(String.init($0)) }
guard locations.count == 2 else { return nil }

self.time = time
Expand All @@ -50,10 +50,10 @@ struct CompileMeasure {
}

init?(rawPath: String, time: Double) {
let untrimmedFilename = rawPath.characters.split(separator: "/").map(String.init).last
let untrimmedFilename = rawPath.split(separator: "/").map(String.init).last

guard let filepath = rawPath.characters.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.characters.split(separator: ":").map(String.init).first else { return nil }
guard let filepath = rawPath.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.split(separator: ":").map(String.init).first else { return nil }

self.time = time
self.code = ""
Expand Down
2 changes: 1 addition & 1 deletion BuildTimeAnalyzer/Info.plist
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.6</string>
<string>1.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
12 changes: 6 additions & 6 deletions BuildTimeAnalyzer/LogProcessor.swift
Expand Up @@ -41,7 +41,7 @@ extension LogProcessorProtocol {
processingDidStart()

while let nextRange = text.rangeOfCharacter(from: characterSet, options: [], range: remainingRange) {
let text = text.substring(with: remainingRange.lowerBound..<nextRange.upperBound)
let text = String(text[remainingRange.lowerBound..<nextRange.upperBound])

defer {
remainingRange = nextRange.upperBound..<remainingRange.upperBound
Expand All @@ -51,9 +51,9 @@ extension LogProcessorProtocol {
let range = NSMakeRange(0, (text as NSString).length)
guard let match = regex.firstMatch(in: text, options: [], range: range) else { continue }

let timeString = text.substring(to: text.characters.index(text.startIndex, offsetBy: match.range.length - 4))
let timeString = text[...text.index(text.startIndex, offsetBy: match.range.length - 4)]
if let time = Double(timeString) {
let value = text.substring(from: text.characters.index(text.startIndex, offsetBy: match.range.length - 1))
let value = String(text[...text.index(text.startIndex, offsetBy: match.range.length - 1)])
if var rawMeasure = rawMeasures[value] {
rawMeasure.time += time
rawMeasure.references += 1
Expand Down Expand Up @@ -86,7 +86,7 @@ extension LogProcessorProtocol {

var result: [CompileMeasure] = []
for entry in unprocessedResult {
let code = entry.text.characters.split(separator: "\t").map(String.init)
let code = entry.text.split(separator: "\t").map(String.init)
let method = code.count >= 2 ? trimPrefixes(code[1]) : "-"

if let path = code.first?.trimmingCharacters(in: characterSet), let measure = CompileMeasure(time: entry.time, rawPath: path, code: method, references: entry.references) {
Expand All @@ -100,7 +100,7 @@ extension LogProcessorProtocol {
var code = code
["@objc ", "final ", "@IBAction "].forEach { (prefix) in
if code.hasPrefix(prefix) {
code = code.substring(from: code.index(code.startIndex, offsetBy: prefix.characters.count))
code = String(code[code.index(code.startIndex, offsetBy: prefix.count)...])
}
}
return code
Expand Down Expand Up @@ -130,7 +130,7 @@ class LogProcessor: NSObject, LogProcessorProtocol {
}
}

func timerCallback(_ timer: Timer) {
@objc func timerCallback(_ timer: Timer) {
updateResults(didComplete: false, didCancel: false)
}
}
2 changes: 1 addition & 1 deletion BuildTimeAnalyzer/ProjectSelection.swift
Expand Up @@ -54,7 +54,7 @@ extension ProjectSelection: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
guard let tableColumn = tableColumn, let columnIndex = tableView.tableColumns.index(of: tableColumn) else { return nil }

let cellView = tableView.make(withIdentifier: "Cell\(columnIndex)", owner: self) as? NSTableCellView
let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell\(columnIndex)"), owner: self) as? NSTableCellView

let source = dataSource[row]
var value = ""
Expand Down
20 changes: 10 additions & 10 deletions BuildTimeAnalyzer/ViewController.swift
Expand Up @@ -49,7 +49,7 @@ class ViewController: NSViewController {
projectSelection.delegate = self
projectSelection.listFolders()

NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(notification:)), name: .NSWindowWillClose, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(notification:)), name: NSWindow.willCloseNotification, object: nil)
}

override func viewWillAppear() {
Expand All @@ -67,7 +67,7 @@ class ViewController: NSViewController {
makeWindowTopMost(topMost: false)
}

func windowWillClose(notification: NSNotification) {
@objc func windowWillClose(notification: NSNotification) {
guard let object = notification.object, !(object is NSPanel) else { return }
NotificationCenter.default.removeObserver(self)

Expand Down Expand Up @@ -142,26 +142,26 @@ class ViewController: NSViewController {
}

func makeWindowTopMost(topMost: Bool) {
if let window = NSApplication.shared().windows.first {
if let window = NSApplication.shared.windows.first {
let level: CGWindowLevelKey = topMost ? .floatingWindow : .normalWindow
window.level = Int(CGWindowLevelForKey(level))
window.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(level)))
}
}

// MARK: Actions

@IBAction func perFileCheckboxClicked(_ sender: NSButton) {
dataSource = sender.state == 0 ? perFunctionTimes : perFileTimes
dataSource = sender.state.rawValue == 0 ? perFunctionTimes : perFileTimes
tableView.reloadData()
}

@IBAction func clipboardButtonClicked(_ sender: AnyObject) {
NSPasteboard.general().clearContents()
NSPasteboard.general().writeObjects(["-Xfrontend -debug-time-function-bodies" as NSPasteboardWriting])
NSPasteboard.general.clearContents()
NSPasteboard.general.writeObjects(["-Xfrontend -debug-time-function-bodies" as NSPasteboardWriting])
}

@IBAction func visitDerivedData(_ sender: AnyObject) {
NSWorkspace.shared().openFile(derivedDataTextField.stringValue)
NSWorkspace.shared.openFile(derivedDataTextField.stringValue)
}


Expand Down Expand Up @@ -283,7 +283,7 @@ extension ViewController: NSTableViewDataSource {

func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
let item = filteredData?[row] ?? dataSource[row]
NSWorkspace.shared().openFile(item.path)
NSWorkspace.shared.openFile(item.path)


let gotoLineScript =
Expand Down Expand Up @@ -312,7 +312,7 @@ extension ViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
guard let tableColumn = tableColumn, let columnIndex = tableView.tableColumns.index(of: tableColumn) else { return nil }

let result = tableView.make(withIdentifier: "Cell\(columnIndex)", owner: self) as? NSTableCellView
let result = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell\(columnIndex)"), owner: self) as? NSTableCellView
result?.textField?.stringValue = filteredData?[row][columnIndex] ?? dataSource[row][columnIndex]

return result
Expand Down

0 comments on commit 75f0e19

Please sign in to comment.