From 4bbd964c2e28912826fcf7ceddbc747f4d865588 Mon Sep 17 00:00:00 2001 From: Andrew Naylor Date: Mon, 14 Sep 2015 09:51:09 +0100 Subject: [PATCH] Update to Swift 2 --- .travis.yml | 4 ++-- Seedfile | 5 ++-- mas-cli.xcodeproj/project.pbxproj | 24 ++++--------------- mas-cli/AppStore/Downloader.swift | 4 ++-- .../AppStore/PurchaseDownloadObserver.swift | 12 +++++----- mas-cli/Commands/Account.swift | 6 ++--- mas-cli/Commands/Install.swift | 6 ++--- mas-cli/Commands/List.swift | 4 ++-- mas-cli/Commands/Outdated.swift | 4 ++-- mas-cli/Error.swift | 2 +- mas-cli/main.swift | 2 +- 11 files changed, 28 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3fcd2c4..8bfad3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: objective-c -xcode_sdk: macosx10.10 -osx_image: xcode6.4 +xcode_sdk: macosx10.11 +osx_image: xcode7 env: global: diff --git a/Seedfile b/Seedfile index 97b7303..ff59ca5 100644 --- a/Seedfile +++ b/Seedfile @@ -1,3 +1,2 @@ -github "Carthage/Commandant", "0.6.1", :files => "Commandant/*.swift" -github "antitypical/Result", "0.4.3", :files => "Result/*.swift" -github "robrix/Box", "1.2.1", :files => "Box/{Box,BoxType,MutableBox}.swift" +github "Carthage/Commandant", "swift-2.0", :files => "Commandant/*.swift" +github "antitypical/Result", "master", :files => "Result/*.swift" diff --git a/mas-cli.xcodeproj/project.pbxproj b/mas-cli.xcodeproj/project.pbxproj index eb51433..1ef2490 100644 --- a/mas-cli.xcodeproj/project.pbxproj +++ b/mas-cli.xcodeproj/project.pbxproj @@ -10,12 +10,11 @@ 1CC607DA6B900AA3FEC3F6D8 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9257C5FABA335E5F060CB7F7 /* Result.swift */; }; 21EC092422A3EDFE33B153B8 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1005EEE43D06F809260BEA /* Command.swift */; }; 5918483F96256CDAC88FF450 /* HelpCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7F27132AB0C6BC7BA7078EF /* HelpCommand.swift */; }; - 66110A826B78DD6BAEC50E70 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7B1825DB425D0D3D345597 /* Box.swift */; }; 6C2E8E6E36A6598C7DA5BAB5 /* ArgumentParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52882737E43AACD9AAEF5D9D /* ArgumentParser.swift */; }; 7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54F23BBFDBCD3D4CAF67DE68 /* Switch.swift */; }; 92828DCD99CED47F54242776 /* Option.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECDEA314BB1F1599638884C /* Option.swift */; }; B80C5DDD38A8F7EB6F320697 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E553CF8A2DE31278400C3A /* Errors.swift */; }; - DE39BCA91D1BC3D876711677 /* MutableBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8007A86176C1DC9462A80FA /* MutableBox.swift */; }; + D40342B675C91E513F04B66E /* ResultType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 580DF177A1A8B1DF500CADA7 /* ResultType.swift */; }; ED031A7C1B5127C00097692E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED031A7B1B5127C00097692E /* main.swift */; }; ED0F237F1B87522400AE40CD /* Install.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F237E1B87522400AE40CD /* Install.swift */; }; ED0F23831B87533A00AE40CD /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F23821B87533A00AE40CD /* List.swift */; }; @@ -28,7 +27,6 @@ EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */; }; EDEAA0C01B51CE6200F2FC3F /* StoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */; }; EDEAA17D1B5C579100F2FC3F /* CommerceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */; }; - F5F01044EC3065C6EBAB95D7 /* BoxType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0E87CFA5E6371893D5B1807 /* BoxType.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -46,10 +44,10 @@ /* Begin PBXFileReference section */ 52882737E43AACD9AAEF5D9D /* ArgumentParser.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ArgumentParser.swift; path = Seeds/Commandant/Commandant/ArgumentParser.swift; sourceTree = ""; }; 54F23BBFDBCD3D4CAF67DE68 /* Switch.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Switch.swift; path = Seeds/Commandant/Commandant/Switch.swift; sourceTree = ""; }; + 580DF177A1A8B1DF500CADA7 /* ResultType.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ResultType.swift; path = Seeds/Result/Result/ResultType.swift; sourceTree = ""; }; 9257C5FABA335E5F060CB7F7 /* Result.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Result.swift; path = Seeds/Result/Result/Result.swift; sourceTree = ""; }; AECDEA314BB1F1599638884C /* Option.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Option.swift; path = Seeds/Commandant/Commandant/Option.swift; sourceTree = ""; }; B7F27132AB0C6BC7BA7078EF /* HelpCommand.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = HelpCommand.swift; path = Seeds/Commandant/Commandant/HelpCommand.swift; sourceTree = ""; }; - B8007A86176C1DC9462A80FA /* MutableBox.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = MutableBox.swift; path = Seeds/Box/Box/MutableBox.swift; sourceTree = ""; }; C4E553CF8A2DE31278400C3A /* Errors.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Errors.swift; path = Seeds/Commandant/Commandant/Errors.swift; sourceTree = ""; }; DD1005EEE43D06F809260BEA /* Command.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Command.swift; path = Seeds/Commandant/Commandant/Command.swift; sourceTree = ""; }; ED031A781B5127C00097692E /* mas-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "mas-cli"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -85,8 +83,6 @@ EDEAA1551B5C576D00F2FC3F /* CKUpdateController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKUpdateController.h; sourceTree = ""; }; EDEAA1661B5C576D00F2FC3F /* ISStoreURLOperationDelegate-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ISStoreURLOperationDelegate-Protocol.h"; sourceTree = ""; }; EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CommerceKit.framework; path = /System/Library/PrivateFrameworks/CommerceKit.framework; sourceTree = ""; }; - F0E87CFA5E6371893D5B1807 /* BoxType.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = BoxType.swift; path = Seeds/Box/Box/BoxType.swift; sourceTree = ""; }; - FC7B1825DB425D0D3D345597 /* Box.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Box.swift; path = Seeds/Box/Box/Box.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -105,27 +101,17 @@ 0739FA024AB80925B32D64D1 /* Seeds */ = { isa = PBXGroup; children = ( - 0DBDF2D12EBF050099F36BEE /* Box */, A49C8EB621015CD588C621FD /* Commandant */, 6569B225928F21A4A639BB22 /* Result */, ); name = Seeds; sourceTree = ""; }; - 0DBDF2D12EBF050099F36BEE /* Box */ = { - isa = PBXGroup; - children = ( - FC7B1825DB425D0D3D345597 /* Box.swift */, - F0E87CFA5E6371893D5B1807 /* BoxType.swift */, - B8007A86176C1DC9462A80FA /* MutableBox.swift */, - ); - name = Box; - sourceTree = ""; - }; 6569B225928F21A4A639BB22 /* Result */ = { isa = PBXGroup; children = ( 9257C5FABA335E5F060CB7F7 /* Result.swift */, + 580DF177A1A8B1DF500CADA7 /* ResultType.swift */, ); name = Result; sourceTree = ""; @@ -308,8 +294,6 @@ files = ( ED0F23871B87537200AE40CD /* Account.swift in Sources */, 6C2E8E6E36A6598C7DA5BAB5 /* ArgumentParser.swift in Sources */, - 66110A826B78DD6BAEC50E70 /* Box.swift in Sources */, - F5F01044EC3065C6EBAB95D7 /* BoxType.swift in Sources */, 21EC092422A3EDFE33B153B8 /* Command.swift in Sources */, ED0F238B1B87569C00AE40CD /* Downloader.swift in Sources */, ED0F238D1B8756E600AE40CD /* Error.swift in Sources */, @@ -319,11 +303,11 @@ ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */, ED0F23831B87533A00AE40CD /* List.swift in Sources */, ED031A7C1B5127C00097692E /* main.swift in Sources */, - DE39BCA91D1BC3D876711677 /* MutableBox.swift in Sources */, 92828DCD99CED47F54242776 /* Option.swift in Sources */, ED0F23851B87536A00AE40CD /* Outdated.swift in Sources */, ED0F23891B87543D00AE40CD /* PurchaseDownloadObserver.swift in Sources */, 1CC607DA6B900AA3FEC3F6D8 /* Result.swift in Sources */, + D40342B675C91E513F04B66E /* ResultType.swift in Sources */, EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */, 7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */, ); diff --git a/mas-cli/AppStore/Downloader.swift b/mas-cli/AppStore/Downloader.swift index 1b3e776..d49e6fb 100644 --- a/mas-cli/AppStore/Downloader.swift +++ b/mas-cli/AppStore/Downloader.swift @@ -21,7 +21,7 @@ func download(adamId: UInt64) -> MASError? { return } - if let downloads = response.downloads as? [SSDownload] where count(downloads) > 0 { + if let downloads = response.downloads as? [SSDownload] where downloads.count > 0 { let observer = PurchaseDownloadObserver(purchase: purchase) observer.errorHandler = { error in @@ -36,7 +36,7 @@ func download(adamId: UInt64) -> MASError? { CKDownloadQueue.sharedDownloadQueue().addObserver(observer) } else { - println("No downloads") + print("No downloads") purchaseError = MASError(code: .NoDownloads) dispatch_group_leave(group) } diff --git a/mas-cli/AppStore/PurchaseDownloadObserver.swift b/mas-cli/AppStore/PurchaseDownloadObserver.swift index e75f34c..3f8d626 100644 --- a/mas-cli/AppStore/PurchaseDownloadObserver.swift +++ b/mas-cli/AppStore/PurchaseDownloadObserver.swift @@ -8,7 +8,7 @@ let csi = "\u{001B}[" -@objc class PurchaseDownloadObserver: CKDownloadQueueObserver { +@objc class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver { let purchase: SSPurchase var completionHandler: (() -> ())? var errorHandler: ((MASError) -> ())? @@ -31,22 +31,22 @@ let csi = "\u{001B}[" } func downloadQueue(queue: CKDownloadQueue, changedWithAddition download: SSDownload!) { - println("==> Downloading " + download.metadata.title) + print("==> Downloading " + download.metadata.title) } func downloadQueue(queue: CKDownloadQueue, changedWithRemoval download: SSDownload!) { clearLine() let status = download.status if status.failed { - println("==> Download Failed") + print("==> Download Failed") errorHandler?(MASError(code: .DownloadFailed, sourceError: status.error)) } else if status.cancelled { - println("==> Download Cancelled") + print("==> Download Cancelled") errorHandler?(MASError(code: .Cancelled)) } else { - println("==> Installed " + download.metadata.title) + print("==> Installed " + download.metadata.title) completionHandler?() } } @@ -80,7 +80,7 @@ func progress(state: ProgressState) { } } clearLine() - print("\(bar) \(state.percentage) \(state.phase)") + print("\(bar) \(state.percentage) \(state.phase)", terminator: "") fflush(stdout) } diff --git a/mas-cli/Commands/Account.swift b/mas-cli/Commands/Account.swift index 0b9fd50..683cae8 100644 --- a/mas-cli/Commands/Account.swift +++ b/mas-cli/Commands/Account.swift @@ -14,15 +14,15 @@ struct AccountCommand: CommandType { switch mode { case .Arguments: if let account = ISStoreAccount.primaryAccount { - println(account.identifier) + print(account.identifier) } else { - println("Not signed in") + print("Not signed in") exit(MASErrorCode.NotSignedIn.exitCode) } default: break } - return .success(()) + return .Success(()) } } diff --git a/mas-cli/Commands/Install.swift b/mas-cli/Commands/Install.swift index 8221737..b8494d4 100644 --- a/mas-cli/Commands/Install.swift +++ b/mas-cli/Commands/Install.swift @@ -18,11 +18,11 @@ struct InstallCommand: CommandType { return .Failure(error) case let .Success(options): - if let error = download(options.value.appId) { - return .failure(CommandantError.CommandError(Box(error))) + if let error = download(options.appId) { + return .Failure(CommandantError.CommandError(error)) } - return .success(()) + return .Success(()) } } } diff --git a/mas-cli/Commands/List.swift b/mas-cli/Commands/List.swift index 7d71b67..ea307d2 100644 --- a/mas-cli/Commands/List.swift +++ b/mas-cli/Commands/List.swift @@ -16,12 +16,12 @@ struct ListCommand: CommandType { let softwareMap = CKSoftwareMap.sharedSoftwareMap() let products = softwareMap.allProducts() as! [CKSoftwareProduct] for product in products { - println("\(product.itemIdentifier) \(product.appName)") + print("\(product.itemIdentifier) \(product.appName)") } default: break } - return .success(()) + return .Success(()) } } \ No newline at end of file diff --git a/mas-cli/Commands/Outdated.swift b/mas-cli/Commands/Outdated.swift index b118f46..e575dcc 100644 --- a/mas-cli/Commands/Outdated.swift +++ b/mas-cli/Commands/Outdated.swift @@ -16,11 +16,11 @@ struct OutdatedCommand: CommandType { let updateController = CKUpdateController.sharedUpdateController() let updates = updateController.availableUpdates() as! [CKUpdate] for update in updates { - println("\(update.itemIdentifier) \(update.title) \(update.actionParams)") + print("\(update.itemIdentifier) \(update.title) \(update.actionParams)") } default: break } - return .success(()) + return .Success(()) } } \ No newline at end of file diff --git a/mas-cli/Error.swift b/mas-cli/Error.swift index 47bfd25..f95857a 100644 --- a/mas-cli/Error.swift +++ b/mas-cli/Error.swift @@ -29,7 +29,7 @@ public class MASError: NSError { } var sourceError: NSError? { - return userInfo?[MASErrorSource] as? NSError + return userInfo[MASErrorSource] as? NSError } convenience init(code: MASErrorCode, sourceError: NSError? = nil) { diff --git a/mas-cli/main.swift b/mas-cli/main.swift index f921255..1c1f788 100644 --- a/mas-cli/main.swift +++ b/mas-cli/main.swift @@ -25,7 +25,7 @@ registry.register(helpCommand) registry.main(defaultVerb: helpCommand.verb) { error in if let sourceError = error.sourceError { var stderr = StderrOutputStream() - println(sourceError.localizedDescription, &stderr) + print(sourceError.localizedDescription, toStream: &stderr) } exit(Int32(error.code)) }