From 79bee5720719699957f5f61bb6d8632a7dad475d Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 2 Mar 2016 18:36:25 +0000 Subject: [PATCH] - fixes crash in #247 - updated for Xcode7.3b5, thus for new Swift version --- BuildaGitServer/GitHub/GitHubBranch.swift | 6 +- BuildaGitServer/GitHub/GitHubComment.swift | 6 +- BuildaGitServer/GitHub/GitHubCommit.swift | 4 +- BuildaGitServer/GitHub/GitHubEntity.swift | 16 ++-- BuildaGitServer/GitHub/GitHubIssue.swift | 4 +- .../GitHub/GitHubPullRequest.swift | 8 +- .../GitHub/GitHubPullRequestBranch.swift | 10 ++- BuildaGitServer/GitHub/GitHubRepo.swift | 4 +- BuildaGitServer/GitHub/GitHubServer.swift | 76 ++++++++++++------- BuildaGitServer/GitHub/GitHubStatus.swift | 6 +- BuildaGitServer/GitHub/GitHubUser.swift | 4 +- BuildaGitServerTests/GitHubServerTests.swift | 22 +++--- BuildaHeartbeatKit/Heartbeat.swift | 4 +- BuildaKit/Project.swift | 2 +- BuildaKit/StorageManager.swift | 6 +- BuildaKit/Syncer.swift | 2 +- BuildaKitTests/Mocks.swift | 32 ++++---- BuildaKitTests/SyncPair_PR_Bot_Tests.swift | 4 +- Buildasaur/AppDelegate.swift | 2 +- Buildasaur/MenuItemManager.swift | 5 +- Buildasaur/TriggerViewController.swift | 4 +- 21 files changed, 128 insertions(+), 99 deletions(-) diff --git a/BuildaGitServer/GitHub/GitHubBranch.swift b/BuildaGitServer/GitHub/GitHubBranch.swift index 84948bd..635ed06 100644 --- a/BuildaGitServer/GitHub/GitHubBranch.swift +++ b/BuildaGitServer/GitHub/GitHubBranch.swift @@ -13,11 +13,11 @@ class GitHubBranch : GitHubEntity { let name: String let commit: GitHubCommit - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.name = json.stringForKey("name") - self.commit = GitHubCommit(json: json.dictionaryForKey("commit")) - super.init(json: json) + self.commit = try GitHubCommit(json: json.dictionaryForKey("commit")) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubComment.swift b/BuildaGitServer/GitHub/GitHubComment.swift index b0e2b92..c190f70 100644 --- a/BuildaGitServer/GitHub/GitHubComment.swift +++ b/BuildaGitServer/GitHub/GitHubComment.swift @@ -13,12 +13,12 @@ class GitHubComment : GitHubEntity { let body: String let author: GitHubUser - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.body = json.stringForKey("body") - self.author = GitHubUser(json: json.dictionaryForKey("user")) + self.author = try GitHubUser(json: json.dictionaryForKey("user")) - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubCommit.swift b/BuildaGitServer/GitHub/GitHubCommit.swift index e61eb48..e60c553 100644 --- a/BuildaGitServer/GitHub/GitHubCommit.swift +++ b/BuildaGitServer/GitHub/GitHubCommit.swift @@ -13,11 +13,11 @@ class GitHubCommit : GitHubEntity { let sha: String - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.sha = json.stringForKey("sha") - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubEntity.swift b/BuildaGitServer/GitHub/GitHubEntity.swift index be07638..87b7d27 100644 --- a/BuildaGitServer/GitHub/GitHubEntity.swift +++ b/BuildaGitServer/GitHub/GitHubEntity.swift @@ -9,7 +9,7 @@ import Foundation protocol GitHubType { - init(json: NSDictionary) + init(json: NSDictionary) throws } class GitHubEntity : GitHubType { @@ -19,7 +19,7 @@ class GitHubEntity : GitHubType { let id: Int? //initializer which takes a dictionary and fills in values for recognized keys - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.htmlUrl = json.optionalStringForKey("html_url") self.url = json.optionalStringForKey("url") @@ -37,9 +37,9 @@ class GitHubEntity : GitHubType { return NSDictionary() } - class func optional(json: NSDictionary?) -> T? { + class func optional(json: NSDictionary?) throws -> T? { if let json = json { - return T(json: json) + return try T(json: json) } return nil } @@ -47,12 +47,12 @@ class GitHubEntity : GitHubType { } //parse an array of dictionaries into an array of parsed entities -func GitHubArray(jsonArray: NSArray!) -> [T] { +func GitHubArray(jsonArray: NSArray!) throws -> [T] { - let array = jsonArray as! [NSDictionary]! - let parsed = array.map { + let array = jsonArray as! [NSDictionary] + let parsed = try array.map { (json: NSDictionary) -> (T) in - return T(json: json) + return try T(json: json) } return parsed } diff --git a/BuildaGitServer/GitHub/GitHubIssue.swift b/BuildaGitServer/GitHub/GitHubIssue.swift index 2d7e268..49897dd 100644 --- a/BuildaGitServer/GitHub/GitHubIssue.swift +++ b/BuildaGitServer/GitHub/GitHubIssue.swift @@ -14,13 +14,13 @@ class GitHubIssue : GitHubEntity { let body: String var title: String - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.number = json.intForKey("number") self.body = json.stringForKey("body") self.title = json.stringForKey("title") - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubPullRequest.swift b/BuildaGitServer/GitHub/GitHubPullRequest.swift index 6528186..cb76017 100644 --- a/BuildaGitServer/GitHub/GitHubPullRequest.swift +++ b/BuildaGitServer/GitHub/GitHubPullRequest.swift @@ -13,12 +13,12 @@ class GitHubPullRequest : GitHubIssue, PullRequestType { let head: GitHubPullRequestBranch let base: GitHubPullRequestBranch - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { - self.head = GitHubPullRequestBranch(json: json.dictionaryForKey("head")) - self.base = GitHubPullRequestBranch(json: json.dictionaryForKey("base")) + self.head = try GitHubPullRequestBranch(json: json.dictionaryForKey("head")) + self.base = try GitHubPullRequestBranch(json: json.dictionaryForKey("base")) - super.init(json: json) + try super.init(json: json) } var headName: String { diff --git a/BuildaGitServer/GitHub/GitHubPullRequestBranch.swift b/BuildaGitServer/GitHub/GitHubPullRequestBranch.swift index 48660a0..7c10a97 100644 --- a/BuildaGitServer/GitHub/GitHubPullRequestBranch.swift +++ b/BuildaGitServer/GitHub/GitHubPullRequestBranch.swift @@ -7,6 +7,7 @@ // import Foundation +import BuildaUtils //PullRequestBranch is a special type of a branch - it also includes repo info (bc PRs can be cross repos) //normal branches include less information @@ -16,13 +17,16 @@ class GitHubPullRequestBranch : GitHubEntity { let sha: String let repo: GitHubRepo - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.ref = json.stringForKey("ref") self.sha = json.stringForKey("sha") - self.repo = GitHubRepo(json: json.dictionaryForKey("repo")) + guard let repo = json.optionalDictionaryForKey("repo") else { + throw Error.withInfo("PR missing information about its repository") + } + self.repo = try GitHubRepo(json: repo) - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubRepo.swift b/BuildaGitServer/GitHub/GitHubRepo.swift index c07f407..ef9de60 100644 --- a/BuildaGitServer/GitHub/GitHubRepo.swift +++ b/BuildaGitServer/GitHub/GitHubRepo.swift @@ -18,7 +18,7 @@ class GitHubRepo : GitHubEntity { var latestRateLimitInfo: RateLimitType? - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.name = json.stringForKey("name") self.fullName = json.stringForKey("full_name") @@ -31,7 +31,7 @@ class GitHubRepo : GitHubEntity { self.permissionsDict = NSDictionary() } - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServer/GitHub/GitHubServer.swift b/BuildaGitServer/GitHub/GitHubServer.swift index 115edb8..d515dad 100644 --- a/BuildaGitServer/GitHub/GitHubServer.swift +++ b/BuildaGitServer/GitHub/GitHubServer.swift @@ -284,8 +284,9 @@ extension GitHubServer { return } - if let body = body as? NSArray { - let prs: [GitHubPullRequest] = GitHubArray(body) + if + let body = body as? NSArray, + let prs: [GitHubPullRequest] = try? GitHubArray(body) { completion(prs: prs, error: nil) } else { completion(prs: nil, error: Error.withInfo("Wrong body \(body)")) @@ -310,8 +311,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let pr = GitHubPullRequest(json: body) + if + let body = body as? NSDictionary, + let pr = try? GitHubPullRequest(json: body) + { completion(pr: pr, error: nil) } else { completion(pr: nil, error: Error.withInfo("Wrong body \(body)")) @@ -334,8 +337,9 @@ extension GitHubServer { return } - if let body = body as? NSArray { - let issues: [GitHubIssue] = GitHubArray(body) + if + let body = body as? NSArray, + let issues: [GitHubIssue] = try? GitHubArray(body) { completion(issues: issues, error: nil) } else { completion(issues: nil, error: Error.withInfo("Wrong body \(body)")) @@ -360,8 +364,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let issue = GitHubIssue(json: body) + if + let body = body as? NSDictionary, + let issue = try? GitHubIssue(json: body) + { completion(issue: issue, error: nil) } else { completion(issue: nil, error: Error.withInfo("Wrong body \(body)")) @@ -390,8 +396,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let issue = GitHubIssue(json: body) + if + let body = body as? NSDictionary, + let issue = try? GitHubIssue(json: body) + { completion(issue: issue, error: nil) } else { completion(issue: nil, error: Error.withInfo("Wrong body \(body)")) @@ -420,8 +428,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let issue = GitHubIssue(json: body) + if + let body = body as? NSDictionary, + let issue = try? GitHubIssue(json: body) + { completion(issue: issue, error: nil) } else { completion(issue: nil, error: Error.withInfo("Wrong body \(body)")) @@ -446,8 +456,10 @@ extension GitHubServer { return } - if let body = body as? NSArray { - let statuses: [GitHubStatus] = GitHubArray(body) + if + let body = body as? NSArray, + let statuses: [GitHubStatus] = try? GitHubArray(body) + { //sort them by creation date let mostRecentStatus = statuses.sort({ return $0.created! > $1.created! }).first completion(status: mostRecentStatus, error: nil) @@ -475,8 +487,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let status = GitHubStatus(json: body) + if + let body = body as? NSDictionary, + let status = try? GitHubStatus(json: body) + { completion(status: status, error: nil) } else { completion(status: nil, error: Error.withInfo("Wrong body \(body)")) @@ -503,8 +517,10 @@ extension GitHubServer { return } - if let body = body as? NSArray { - let comments: [GitHubComment] = GitHubArray(body) + if + let body = body as? NSArray, + let comments: [GitHubComment] = try? GitHubArray(body) + { completion(comments: comments, error: nil) } else { completion(comments: nil, error: Error.withInfo("Wrong body \(body)")) @@ -533,8 +549,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let comment = GitHubComment(json: body) + if + let body = body as? NSDictionary, + let comment = try? GitHubComment(json: body) + { completion(comment: comment, error: nil) } else { completion(comment: nil, error: Error.withInfo("Wrong body \(body)")) @@ -563,8 +581,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let comment = GitHubComment(json: body) + if + let body = body as? NSDictionary, + let comment = try? GitHubComment(json: body) + { completion(comment: comment, error: nil) } else { completion(comment: nil, error: Error.withInfo("Wrong body \(body)")) @@ -641,8 +661,10 @@ extension GitHubServer { return } - if let body = body as? NSArray { - let branches: [GitHubBranch] = GitHubArray(body) + if + let body = body as? NSArray, + let branches: [GitHubBranch] = try? GitHubArray(body) + { completion(branches: branches, error: nil) } else { completion(branches: nil, error: Error.withInfo("Wrong body \(body)")) @@ -667,8 +689,10 @@ extension GitHubServer { return } - if let body = body as? NSDictionary { - let repository: GitHubRepo = GitHubRepo(json: body) + if + let body = body as? NSDictionary, + let repository: GitHubRepo = try? GitHubRepo(json: body) + { completion(repo: repository, error: nil) } else { completion(repo: nil, error: Error.withInfo("Wrong body \(body)")) diff --git a/BuildaGitServer/GitHub/GitHubStatus.swift b/BuildaGitServer/GitHub/GitHubStatus.swift index 2cc4654..0f2e239 100644 --- a/BuildaGitServer/GitHub/GitHubStatus.swift +++ b/BuildaGitServer/GitHub/GitHubStatus.swift @@ -56,7 +56,7 @@ class GitHubStatus : GitHubEntity { let created: String? let creator: GitHubUser? - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.githubState = GitHubState(rawValue: json.stringForKey("state"))! self.description = json.optionalStringForKey("description") @@ -64,12 +64,12 @@ class GitHubStatus : GitHubEntity { self.context = json.optionalStringForKey("context") self.created = json.optionalStringForKey("created_at") if let creator = json.optionalDictionaryForKey("creator") { - self.creator = GitHubUser(json: creator) + self.creator = try GitHubUser(json: creator) } else { self.creator = nil } - super.init(json: json) + try super.init(json: json) } init(state: GitHubState, description: String?, targetUrl: String?, context: String?) { diff --git a/BuildaGitServer/GitHub/GitHubUser.swift b/BuildaGitServer/GitHub/GitHubUser.swift index c9a06a1..b87321e 100644 --- a/BuildaGitServer/GitHub/GitHubUser.swift +++ b/BuildaGitServer/GitHub/GitHubUser.swift @@ -14,13 +14,13 @@ class GitHubUser : GitHubEntity { let realName: String? let avatarUrl: String? - required init(json: NSDictionary) { + required init(json: NSDictionary) throws { self.userName = json.stringForKey("login") self.realName = json.optionalStringForKey("name") self.avatarUrl = json.stringForKey("avatar_url") - super.init(json: json) + try super.init(json: json) } } diff --git a/BuildaGitServerTests/GitHubServerTests.swift b/BuildaGitServerTests/GitHubServerTests.swift index 711688f..90c5d14 100644 --- a/BuildaGitServerTests/GitHubServerTests.swift +++ b/BuildaGitServerTests/GitHubServerTests.swift @@ -44,17 +44,17 @@ class GitHubSourceTests: XCTestCase { } func testGetPullRequests() { - + let params = [ "repo": "czechboy0/Buildasaur-Tester" ] - + self.tryEndpoint(.GET, endpoint: .PullRequests, params: params) { (body, error) -> () in XCTAssertNotNil(body, "Body must be non-nil") if let body = body as? NSArray { - let prs: [GitHubPullRequest] = GitHubArray(body) - XCTAssertGreaterThan(prs.count, 0, "We need > 0 items to test parsing") + let prs: [GitHubPullRequest]? = try? GitHubArray(body) + XCTAssertGreaterThan(prs?.count ?? -1, 0, "We need > 0 items to test parsing") Log.verbose("Parsed PRs: \(prs)") } else { XCTFail("Body nil") @@ -72,8 +72,8 @@ class GitHubSourceTests: XCTestCase { XCTAssertNotNil(body, "Body must be non-nil") if let body = body as? NSArray { - let branches: [GitHubBranch] = GitHubArray(body) - XCTAssertGreaterThan(branches.count, 0, "We need > 0 items to test parsing") + let branches: [GitHubBranch]? = try? GitHubArray(body) + XCTAssertGreaterThan(branches?.count ?? -1, 0, "We need > 0 items to test parsing") Log.verbose("Parsed branches: \(branches)") } else { XCTFail("Body nil") @@ -92,7 +92,7 @@ class GitHubSourceTests: XCTestCase { "html_url": "https://github.com/czechboy0" ] - let user = GitHubUser(json: dictionary) + let user = try! GitHubUser(json: dictionary) XCTAssertEqual(user.userName, "czechboy0") XCTAssertEqual(user.realName!, "Honza Dvorsky") XCTAssertEqual(user.avatarUrl!, "https://avatars.githubusercontent.com/u/2182121?v=3") @@ -109,7 +109,7 @@ class GitHubSourceTests: XCTestCase { "html_url": "https://github.com/czechboy0/Buildasaur" ] - let repo = GitHubRepo(json: dictionary) + let repo = try! GitHubRepo(json: dictionary) XCTAssertEqual(repo.name, "Buildasaur") XCTAssertEqual(repo.fullName, "czechboy0/Buildasaur") XCTAssertEqual(repo.repoUrlHTTPS, "https://github.com/czechboy0/Buildasaur.git") @@ -124,7 +124,7 @@ class GitHubSourceTests: XCTestCase { "url": "https://api.github.com/repos/czechboy0/Buildasaur/commits/08182438ed2ef3b34bd97db85f39deb60e2dcd7d" ] - let commit = GitHubCommit(json: dictionary) + let commit = try! GitHubCommit(json: dictionary) XCTAssertEqual(commit.sha, "08182438ed2ef3b34bd97db85f39deb60e2dcd7d") XCTAssertEqual(commit.url!, "https://api.github.com/repos/czechboy0/Buildasaur/commits/08182438ed2ef3b34bd97db85f39deb60e2dcd7d") } @@ -140,7 +140,7 @@ class GitHubSourceTests: XCTestCase { "commit": commitDictionary ] - let branch = GitHubBranch(json: dictionary) + let branch = try! GitHubBranch(json: dictionary) XCTAssertEqual(branch.name, "master") XCTAssertEqual(branch.commit.sha, "08182438ed2ef3b34bd97db85f39deb60e2dcd7d") XCTAssertEqual(branch.commit.url!, "https://api.github.com/repos/czechboy0/Buildasaur/commits/08182438ed2ef3b34bd97db85f39deb60e2dcd7d") @@ -174,7 +174,7 @@ class GitHubSourceTests: XCTestCase { ] ] - let prbranch = GitHubPullRequestBranch(json: dictionary) + let prbranch = try! GitHubPullRequestBranch(json: dictionary) XCTAssertEqual(prbranch.ref, "fb-loadNode") XCTAssertEqual(prbranch.sha, "7e45fa772565969ee801b0bdce0f560122e34610") XCTAssertEqual(prbranch.repo.name, "AsyncDisplayKit") diff --git a/BuildaHeartbeatKit/Heartbeat.swift b/BuildaHeartbeatKit/Heartbeat.swift index 80dcdce..108fc9a 100644 --- a/BuildaHeartbeatKit/Heartbeat.swift +++ b/BuildaHeartbeatKit/Heartbeat.swift @@ -94,7 +94,7 @@ public protocol HeartbeatManagerDelegate { self.initialTimer = NSTimer.scheduledTimerWithTimeInterval( 20, target: self, - selector: "_timerFired:", + selector: #selector(_timerFired(_:)), userInfo: nil, repeats: false) @@ -102,7 +102,7 @@ public protocol HeartbeatManagerDelegate { self.timer = NSTimer.scheduledTimerWithTimeInterval( self.interval, target: self, - selector: "_timerFired:", + selector: #selector(_timerFired(_:)), userInfo: nil, repeats: true) } diff --git a/BuildaKit/Project.swift b/BuildaKit/Project.swift index 88feaf4..0e388d3 100644 --- a/BuildaKit/Project.swift +++ b/BuildaKit/Project.swift @@ -93,7 +93,7 @@ public class Project { */ let serviceUrl = service.hostname().lowercaseString - let dotGitRange = stringUrl.rangeOfString(".git", options: NSStringCompareOptions.BackwardsSearch, range: nil, locale: nil) ?? Range(start: stringUrl.endIndex, end: stringUrl.endIndex) + let dotGitRange = stringUrl.rangeOfString(".git", options: NSStringCompareOptions.BackwardsSearch, range: nil, locale: nil) ?? stringUrl.endIndex.. ProjectConfig in + (_p: ProjectConfig) -> ProjectConfig in + var p = _p var auth: ProjectAuthenticator? if let val = tokenKeychain.read(p.keychainKey()) { auth = try? ProjectAuthenticator.fromString(val) @@ -195,7 +196,8 @@ public class StorageManager { let xcsConfigKeychain = self.serverConfigKeychain self.serverConfigs.value = allServerConfigs .map { - (var x: XcodeServerConfig) -> XcodeServerConfig in + (_x: XcodeServerConfig) -> XcodeServerConfig in + var x = _x x.password = xcsConfigKeychain.read(x.keychainKey()) return x }.dictionarifyWithKey { $0.id } diff --git a/BuildaKit/Syncer.swift b/BuildaKit/Syncer.swift index 50a17c0..f20c720 100644 --- a/BuildaKit/Syncer.swift +++ b/BuildaKit/Syncer.swift @@ -61,7 +61,7 @@ class Trampoline: NSObject { public var active: Bool { didSet { if active && !oldValue { - let s = Selector("jump") + let s = #selector(Trampoline.jump) let timer = NSTimer(timeInterval: self.syncInterval, target: self.trampoline, selector: s, userInfo: nil, repeats: true) self.timer = timer NSRunLoop.mainRunLoop().addTimer(timer, forMode: kCFRunLoopCommonModes as String) diff --git a/BuildaKitTests/Mocks.swift b/BuildaKitTests/Mocks.swift index 4e1211f..02ff2af 100644 --- a/BuildaKitTests/Mocks.swift +++ b/BuildaKitTests/Mocks.swift @@ -28,7 +28,7 @@ class MockGitHubServer: GitHubServer { class MockProject: Project { init() { - let path: String = __FILE__ + let path: String = #file let folder = (path as NSString).stringByDeletingLastPathComponent let testProject = "\(folder)/TestProjects/Buildasaur-TestProject-iOS/Buildasaur-TestProject-iOS.xcworkspace" var config = ProjectConfig() @@ -57,11 +57,11 @@ class MockRepo: GitHubRepo { } convenience init() { - self.init(json: MockRepo.mockDictionary()) + try! self.init(json: MockRepo.mockDictionary()) } - required init(json: NSDictionary) { - super.init(json: json) + required init(json: NSDictionary) throws { + try super.init(json: json) } } @@ -77,11 +77,11 @@ class MockBranch: GitHubBranch { } convenience init(name: String = "master", sha: String = "1234f") { - self.init(json: MockBranch.mockDictionary(name, sha: sha)) + try! self.init(json: MockBranch.mockDictionary(name, sha: sha)) } - required init(json: NSDictionary) { - super.init(json: json) + required init(json: NSDictionary) throws { + try super.init(json: json) } } @@ -96,11 +96,11 @@ class MockPullRequestBranch: GitHubPullRequestBranch { } convenience init() { - self.init(json: MockPullRequestBranch.mockDictionary()) + try! self.init(json: MockPullRequestBranch.mockDictionary()) } - required init(json: NSDictionary) { - super.init(json: json) + required init(json: NSDictionary) throws { + try super.init(json: json) } } @@ -115,11 +115,11 @@ class MockIssue: GitHubIssue { } convenience init() { - self.init(json: MockIssue.mockDictionary()) + try! self.init(json: MockIssue.mockDictionary()) } - required init(json: NSDictionary) { - super.init(json: json) + required init(json: NSDictionary) throws { + try super.init(json: json) } } @@ -148,11 +148,11 @@ class MockPullRequest: GitHubPullRequest { } convenience init(number: Int = 1, title: String = "PR title") { - self.init(json: MockPullRequest.mockDictionary(number, title: title)) + try! self.init(json: MockPullRequest.mockDictionary(number, title: title)) } - required init(json: NSDictionary) { - super.init(json: json) + required init(json: NSDictionary) throws { + try super.init(json: json) } } diff --git a/BuildaKitTests/SyncPair_PR_Bot_Tests.swift b/BuildaKitTests/SyncPair_PR_Bot_Tests.swift index 01ee448..12a3b1d 100644 --- a/BuildaKitTests/SyncPair_PR_Bot_Tests.swift +++ b/BuildaKitTests/SyncPair_PR_Bot_Tests.swift @@ -16,12 +16,12 @@ import BuildaKit //for tuples, XCTAssert... doesn't work for them func XCTBAssertNil(@autoclosure expression: () -> T?, message: String = "Must be nil", - file: StaticString = __FILE__, line: UInt = __LINE__) { + file: StaticString = #file, line: UInt = #line) { XCTAssert(expression() == nil, message, file:file, line:line); } func XCTBAssertNotNil(@autoclosure expression: () -> T?, message: String = "Must not be nil", - file: StaticString = __FILE__, line: UInt = __LINE__) { + file: StaticString = #file, line: UInt = #line) { XCTAssert(expression() != nil, message, file:file, line:line); } diff --git a/Buildasaur/AppDelegate.swift b/Buildasaur/AppDelegate.swift index ae60e2f..c7b7197 100644 --- a/Buildasaur/AppDelegate.swift +++ b/Buildasaur/AppDelegate.swift @@ -213,7 +213,7 @@ extension AppDelegate { func setupURLCallback() { // listen to scheme url - NSAppleEventManager.sharedAppleEventManager().setEventHandler(self, andSelector:"handleGetURLEvent:withReplyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL)) + NSAppleEventManager.sharedAppleEventManager().setEventHandler(self, andSelector:#selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL)) } func handleGetURLEvent(event: NSAppleEventDescriptor!, withReplyEvent: NSAppleEventDescriptor!) { diff --git a/Buildasaur/MenuItemManager.swift b/Buildasaur/MenuItemManager.swift index 04db60c..27d4070 100644 --- a/Buildasaur/MenuItemManager.swift +++ b/Buildasaur/MenuItemManager.swift @@ -26,8 +26,7 @@ class MenuItemManager : NSObject, NSMenuDelegate { statusItem.highlightMode = true let menu = NSMenu() - menu.addItemWithTitle("Open Buildasaur", action: "showMainWindow", keyEquivalent: "") - menu.addItemWithTitle("Quit Buildasaur", action: "terminate:", keyEquivalent: "") + menu.addItemWithTitle("Open Buildasaur", action: #selector(AppDelegate.showMainWindow), keyEquivalent: "") menu.addItem(NSMenuItem.separatorItem()) self.firstIndexLastSyncedMenuItem = menu.numberOfItems @@ -48,7 +47,7 @@ class MenuItemManager : NSObject, NSMenuDelegate { //this many items need to be created or destroyed if diffItems > 0 { for _ in 0..