Skip to content

Commit 75f0e19

Browse files
author
Robert Gummesson
authored
Merge pull request #71 from Nonnus/swift4
migrated to swift4, bumped version to 1.0.7
2 parents feda2bd + f41f389 commit 75f0e19

File tree

9 files changed

+56
-42
lines changed

9 files changed

+56
-42
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
language: objective-c
2-
osx_image: xcode8.2
3-
script: xcodebuild -project BuildTimeAnalyzer.xcodeproj -scheme BuildTimeAnalyzer build test
1+
language: swift
2+
osx_image: xcode9
3+
script: xcodebuild -project BuildTimeAnalyzer.xcodeproj -scheme BuildTimeAnalyzer build test

BuildTimeAnalyzer.xcodeproj/project.pbxproj

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,16 @@
246246
isa = PBXProject;
247247
attributes = {
248248
LastSwiftUpdateCheck = 0730;
249-
LastUpgradeCheck = 0800;
249+
LastUpgradeCheck = 0900;
250250
ORGANIZATIONNAME = "Cane Media Ltd";
251251
TargetAttributes = {
252252
2AF8213F1D21D6B900D65186 = {
253253
CreatedOnToolsVersion = 7.3.1;
254-
LastSwiftMigration = 0800;
254+
LastSwiftMigration = 0900;
255255
};
256256
2AF8214E1D21D6B900D65186 = {
257257
CreatedOnToolsVersion = 7.3.1;
258-
LastSwiftMigration = 0800;
258+
LastSwiftMigration = 0900;
259259
TestTargetID = 2AF8213F1D21D6B900D65186;
260260
};
261261
};
@@ -350,14 +350,20 @@
350350
CLANG_CXX_LIBRARY = "libc++";
351351
CLANG_ENABLE_MODULES = YES;
352352
CLANG_ENABLE_OBJC_ARC = YES;
353+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
353354
CLANG_WARN_BOOL_CONVERSION = YES;
355+
CLANG_WARN_COMMA = YES;
354356
CLANG_WARN_CONSTANT_CONVERSION = YES;
355357
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
356358
CLANG_WARN_EMPTY_BODY = YES;
357359
CLANG_WARN_ENUM_CONVERSION = YES;
358360
CLANG_WARN_INFINITE_RECURSION = YES;
359361
CLANG_WARN_INT_CONVERSION = YES;
362+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
363+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
360364
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
365+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
366+
CLANG_WARN_STRICT_PROTOTYPES = YES;
361367
CLANG_WARN_SUSPICIOUS_MOVE = YES;
362368
CLANG_WARN_UNREACHABLE_CODE = YES;
363369
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -397,14 +403,20 @@
397403
CLANG_CXX_LIBRARY = "libc++";
398404
CLANG_ENABLE_MODULES = YES;
399405
CLANG_ENABLE_OBJC_ARC = YES;
406+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
400407
CLANG_WARN_BOOL_CONVERSION = YES;
408+
CLANG_WARN_COMMA = YES;
401409
CLANG_WARN_CONSTANT_CONVERSION = YES;
402410
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
403411
CLANG_WARN_EMPTY_BODY = YES;
404412
CLANG_WARN_ENUM_CONVERSION = YES;
405413
CLANG_WARN_INFINITE_RECURSION = YES;
406414
CLANG_WARN_INT_CONVERSION = YES;
415+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
416+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
407417
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
418+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
419+
CLANG_WARN_STRICT_PROTOTYPES = YES;
408420
CLANG_WARN_SUSPICIOUS_MOVE = YES;
409421
CLANG_WARN_UNREACHABLE_CODE = YES;
410422
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -438,7 +450,7 @@
438450
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzer;
439451
PRODUCT_NAME = "$(TARGET_NAME)";
440452
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
441-
SWIFT_VERSION = 3.0;
453+
SWIFT_VERSION = 4.0;
442454
};
443455
name = Debug;
444456
};
@@ -452,7 +464,7 @@
452464
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzer;
453465
PRODUCT_NAME = "$(TARGET_NAME)";
454466
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
455-
SWIFT_VERSION = 3.0;
467+
SWIFT_VERSION = 4.0;
456468
};
457469
name = Release;
458470
};
@@ -468,7 +480,7 @@
468480
PRODUCT_NAME = "$(TARGET_NAME)";
469481
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
470482
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
471-
SWIFT_VERSION = 3.0;
483+
SWIFT_VERSION = 4.0;
472484
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BuildTimeAnalyzer.app/Contents/MacOS/BuildTimeAnalyzer";
473485
};
474486
name = Debug;
@@ -484,7 +496,7 @@
484496
PRODUCT_BUNDLE_IDENTIFIER = uk.co.canemedia.BuildTimeAnalyzerTests;
485497
PRODUCT_NAME = "$(TARGET_NAME)";
486498
SWIFT_OBJC_BRIDGING_HEADER = "BuildTimeAnalyzerTests-Bridging-Header.h";
487-
SWIFT_VERSION = 3.0;
499+
SWIFT_VERSION = 4.0;
488500
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BuildTimeAnalyzer.app/Contents/MacOS/BuildTimeAnalyzer";
489501
};
490502
name = Release;

BuildTimeAnalyzer.xcodeproj/xcshareddata/xcschemes/BuildTimeAnalyzer.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -55,6 +56,7 @@
5556
buildConfiguration = "Debug"
5657
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5758
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
language = ""
5860
launchStyle = "0"
5961
useCustomWorkingDirectory = "NO"
6062
ignoresPersistentStateOnLaunch = "NO"

BuildTimeAnalyzer/AppDelegate.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1313
@IBOutlet weak var alwaysInFrontMenuItem: NSMenuItem!
1414

1515
var viewController: ViewController? {
16-
return NSApplication.shared().mainWindow?.contentViewController as? ViewController
16+
return NSApplication.shared.mainWindow?.contentViewController as? ViewController
1717
}
1818

1919
func applicationDidFinishLaunching(_ notification: Notification) {
20-
alwaysInFrontMenuItem.state = UserSettings.windowShouldBeTopMost ? NSOnState : NSOffState
20+
alwaysInFrontMenuItem.state = UserSettings.windowShouldBeTopMost ? .on : .off
2121
}
2222

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

4949
@IBAction func toggleAlwaysInFront(_ sender: NSMenuItem) {
50-
let alwaysInFront = sender.state == NSOffState
50+
let alwaysInFront = sender.state == .off
5151

52-
sender.state = alwaysInFront ? NSOnState : NSOffState
52+
sender.state = alwaysInFront ? .on : .off
5353
UserSettings.windowShouldBeTopMost = alwaysInFront
5454

5555
viewController?.makeWindowTopMost(topMost: alwaysInFront)

BuildTimeAnalyzer/CompileMeasure.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ struct CompileMeasure {
3232
}
3333

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

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

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

4444
self.time = time
@@ -50,10 +50,10 @@ struct CompileMeasure {
5050
}
5151

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

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

5858
self.time = time
5959
self.code = ""

BuildTimeAnalyzer/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.6</string>
20+
<string>1.0.7</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

BuildTimeAnalyzer/LogProcessor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension LogProcessorProtocol {
4141
processingDidStart()
4242

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

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

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

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

9292
if let path = code.first?.trimmingCharacters(in: characterSet), let measure = CompileMeasure(time: entry.time, rawPath: path, code: method, references: entry.references) {
@@ -100,7 +100,7 @@ extension LogProcessorProtocol {
100100
var code = code
101101
["@objc ", "final ", "@IBAction "].forEach { (prefix) in
102102
if code.hasPrefix(prefix) {
103-
code = code.substring(from: code.index(code.startIndex, offsetBy: prefix.characters.count))
103+
code = String(code[code.index(code.startIndex, offsetBy: prefix.count)...])
104104
}
105105
}
106106
return code
@@ -130,7 +130,7 @@ class LogProcessor: NSObject, LogProcessorProtocol {
130130
}
131131
}
132132

133-
func timerCallback(_ timer: Timer) {
133+
@objc func timerCallback(_ timer: Timer) {
134134
updateResults(didComplete: false, didCancel: false)
135135
}
136136
}

BuildTimeAnalyzer/ProjectSelection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension ProjectSelection: NSTableViewDelegate {
5454
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
5555
guard let tableColumn = tableColumn, let columnIndex = tableView.tableColumns.index(of: tableColumn) else { return nil }
5656

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

5959
let source = dataSource[row]
6060
var value = ""

BuildTimeAnalyzer/ViewController.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ViewController: NSViewController {
4949
projectSelection.delegate = self
5050
projectSelection.listFolders()
5151

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

5555
override func viewWillAppear() {
@@ -67,7 +67,7 @@ class ViewController: NSViewController {
6767
makeWindowTopMost(topMost: false)
6868
}
6969

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

@@ -142,26 +142,26 @@ class ViewController: NSViewController {
142142
}
143143

144144
func makeWindowTopMost(topMost: Bool) {
145-
if let window = NSApplication.shared().windows.first {
145+
if let window = NSApplication.shared.windows.first {
146146
let level: CGWindowLevelKey = topMost ? .floatingWindow : .normalWindow
147-
window.level = Int(CGWindowLevelForKey(level))
147+
window.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(level)))
148148
}
149149
}
150150

151151
// MARK: Actions
152152

153153
@IBAction func perFileCheckboxClicked(_ sender: NSButton) {
154-
dataSource = sender.state == 0 ? perFunctionTimes : perFileTimes
154+
dataSource = sender.state.rawValue == 0 ? perFunctionTimes : perFileTimes
155155
tableView.reloadData()
156156
}
157157

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

163163
@IBAction func visitDerivedData(_ sender: AnyObject) {
164-
NSWorkspace.shared().openFile(derivedDataTextField.stringValue)
164+
NSWorkspace.shared.openFile(derivedDataTextField.stringValue)
165165
}
166166

167167

@@ -283,7 +283,7 @@ extension ViewController: NSTableViewDataSource {
283283

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

288288

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

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

318318
return result

0 commit comments

Comments
 (0)