Skip to content

Commit 3de1d1a

Browse files
update to Swift 4
1 parent 1f7ea13 commit 3de1d1a

12 files changed

+56
-32
lines changed

ReSwift-Todo.xcodeproj/project.pbxproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,12 @@
493493
TargetAttributes = {
494494
50703AE21D7EACB8001DAF45 = {
495495
CreatedOnToolsVersion = 7.3.1;
496-
LastSwiftMigration = 0800;
496+
LastSwiftMigration = 1010;
497497
ProvisioningStyle = Manual;
498498
};
499499
50703AF61D7EACB8001DAF45 = {
500500
CreatedOnToolsVersion = 7.3.1;
501-
LastSwiftMigration = 0800;
501+
LastSwiftMigration = 1010;
502502
ProvisioningStyle = Manual;
503503
TestTargetID = 50703AE21D7EACB8001DAF45;
504504
};
@@ -747,7 +747,8 @@
747747
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-Todo";
748748
PRODUCT_MODULE_NAME = ReSwiftTodo;
749749
PRODUCT_NAME = "$(TARGET_NAME)";
750-
SWIFT_VERSION = 3.0;
750+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
751+
SWIFT_VERSION = 4.2;
751752
};
752753
name = Debug;
753754
};
@@ -765,7 +766,8 @@
765766
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-Todo";
766767
PRODUCT_MODULE_NAME = ReSwiftTodo;
767768
PRODUCT_NAME = "$(TARGET_NAME)";
768-
SWIFT_VERSION = 3.0;
769+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
770+
SWIFT_VERSION = 4.2;
769771
};
770772
name = Release;
771773
};
@@ -784,7 +786,8 @@
784786
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-TodoTests";
785787
PRODUCT_NAME = "$(TARGET_NAME)";
786788
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
787-
SWIFT_VERSION = 3.0;
789+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
790+
SWIFT_VERSION = 4.2;
788791
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReSwift-Todo.app/Contents/MacOS/ReSwift-Todo";
789792
};
790793
name = Debug;
@@ -803,7 +806,8 @@
803806
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
804807
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-TodoTests";
805808
PRODUCT_NAME = "$(TARGET_NAME)";
806-
SWIFT_VERSION = 3.0;
809+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
810+
SWIFT_VERSION = 4.2;
807811
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReSwift-Todo.app/Contents/MacOS/ReSwift-Todo";
808812
};
809813
name = Release;

ReSwift-Todo/CheckBox.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Cocoa
1010

1111
class CheckBox: NSButton {
1212
var checked: Bool {
13-
get { return state == NSOnState }
14-
set { state = newValue ? NSOnState : NSOffState }
13+
get { return state == .on }
14+
set { state = newValue ? .on : .off }
1515
}
1616
}

ReSwift-Todo/DateConverter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class DateConverter {
3434
/// (YYYY-MM-DD) and extracts these values.
3535
func date(isoDateString string: String, calendar: Calendar = Calendar.autoupdatingCurrent) -> Date? {
3636

37-
let parts = string.characters.split(separator: "-")
37+
let parts = string.split(separator: "-")
3838
.map(String.init)
39-
.flatMap { Int($0) }
39+
.compactMap { Int($0) }
4040

4141
guard parts.count >= 3 else { return nil }
4242

ReSwift-Todo/ToDoCellView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ToDoCellView: NSTableCellView {
3737

3838
static func make(tableView: NSTableView, owner: AnyObject? = nil) -> ToDoCellView? {
3939

40-
return tableView.make(withIdentifier: ToDoCellView.reuseIdentifier, owner: owner) as? ToDoCellView
40+
return tableView.makeView(withIdentifier: convertToNSUserInterfaceItemIdentifier(ToDoCellView.reuseIdentifier), owner: owner) as? ToDoCellView
4141
}
4242

4343
@IBAction func checkboxChanged(_ sender: AnyObject) {
@@ -62,3 +62,8 @@ extension ToDoCellView: DisplaysToDo {
6262
self.viewModel = viewModel
6363
}
6464
}
65+
66+
// Helper function inserted by Swift 4.2 migrator.
67+
fileprivate func convertToNSUserInterfaceItemIdentifier(_ input: String) -> NSUserInterfaceItemIdentifier {
68+
return NSUserInterfaceItemIdentifier(rawValue: input)
69+
}

ReSwift-Todo/ToDoDocument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ToDoDocument: NSDocument {
3030

3131
// MARK: - Saving/Loading Data
3232

33-
override class func autosavesInPlace() -> Bool {
33+
override class var autosavesInPlace: Bool {
3434
return true
3535
}
3636

ReSwift-Todo/ToDoLineTokenizer.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class ToDoLineTokenizer {
2626

2727
guard !text.isEmpty else { return nil }
2828

29-
if text.characters.first == "-" {
29+
if text.first == "-" {
3030
return toDo(text: text)
3131
}
3232

33-
if text.characters.last == ":" {
33+
if text.last == ":" {
3434
return projectTitle(text: text)
3535
}
3636

@@ -39,9 +39,8 @@ class ToDoLineTokenizer {
3939

4040
fileprivate func toDo(text: String) -> Token? {
4141

42-
let cleanedLine = text
43-
// strip dash
44-
.substring(from: text.characters.index(after: text.startIndex))
42+
// strip dash
43+
let cleanedLine = String(text[text.index(after: text.startIndex)...])
4544
.stringByTrimmingWhitespaceAndNewline()
4645

4746
let words = cleanedLine.components(separatedBy: CharacterSet.whitespacesAndNewlines)
@@ -52,7 +51,7 @@ class ToDoLineTokenizer {
5251

5352
let title = components.0.joined(separator: " ")
5453
let tagWords = components.1.filter(wordIsTag)
55-
.map { $0.characters.dropFirst() } // Drop "@"
54+
.map { $0.dropFirst() } // Drop "@"
5655
.map(String.init)
5756
let result: (completion: Completion, tags: Set<String>) = separateTagsFromCompletion(tagWords)
5857

@@ -83,13 +82,12 @@ class ToDoLineTokenizer {
8382
fileprivate func projectTitle(text: String) -> Token? {
8483

8584
// Drop trailing colon
86-
let title = text.substring(to: text.characters.index(before: text.endIndex))
85+
let title = String(text[..<text.index(before: text.endIndex)])
8786

8887
return .projectTitle(title)
8988
}
9089
}
9190

9291
private func wordIsTag(_ word: String) -> Bool {
93-
94-
return word.characters.first == "@"
92+
return word.first == "@"
9593
}

ReSwift-Todo/ToDoListImporter.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ToDoListImporter {
2727

2828
func importToDoList(text: String) throws -> ToDoList {
2929

30-
let lines = text.characters
30+
let lines = text
3131
.split(omittingEmptySubsequences: false) { $0 == Character(String.newline) }
3232
.map(String.init)
3333

@@ -38,7 +38,7 @@ class ToDoListImporter {
3838

3939
func parse<T: Sequence>(stream: T) -> ToDoList where T.Iterator.Element == String {
4040

41-
var tokens = stream.flatMap(tokenizer.token(text:))
41+
var tokens = stream.compactMap(tokenizer.token(text:))
4242

4343
if let projectTitleIndex = tokens.index(where: tokenIsProjectTitle),
4444
projectTitleIndex > 0 {
@@ -88,7 +88,6 @@ private func tokenIsProjectTitle(_ token: Token) -> Bool {
8888

8989
extension Array {
9090

91-
9291
func split(take n: Index) -> (ArraySlice<Element>, ArraySlice<Element>) {
9392

9493
return (prefix(upTo: n), dropFirst(n))

ReSwift-Todo/ToDoListReducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ToDoListReducer: ReSwift.Reducer {
4545

4646
var toDoList = toDoList
4747

48-
toDoList.items = toDoList.items.flatMap { toDoReducer.handleAction(action, state: $0) }
48+
toDoList.items = toDoList.items.compactMap { toDoReducer.handleAction(action, state: $0) }
4949

5050
return toDoList
5151
}

ReSwift-Todo/ToDoListSerializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ToDoListSerializer {
7373

7474
return [body]
7575
.appendedContentsOf(tags)
76-
.appendedContentsOf([done].flatMap(identity)) // remove nil
76+
.appendedContentsOf([done].compactMap(identity)) // remove nil
7777
.joined(separator: " ")
7878
}
7979
}

ReSwift-Todo/ToDoListWindowController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ToDoListWindowController: NSWindowController {
8282

8383
super.awakeFromNib()
8484

85-
NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(_:)), name: NSNotification.Name.NSWindowWillClose, object: self.window)
85+
NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(_:)), name: NSWindow.willCloseNotification, object: self.window)
8686

8787
tableView.dataSource = self.dataSource.tableDataSource
8888
tableView.delegate = self
@@ -112,7 +112,7 @@ class ToDoListWindowController: NSWindowController {
112112
store?.dispatch(action)
113113
}
114114

115-
func windowWillClose(_ notification: Notification) {
115+
@objc func windowWillClose(_ notification: Notification) {
116116

117117
guard let sendingWindow = notification.object as? NSWindow
118118
, sendingWindow == self.window

0 commit comments

Comments
 (0)