From 9c69f0b1bceb703c2fff79eefccc9776edbc1602 Mon Sep 17 00:00:00 2001 From: beltex Date: Thu, 12 Feb 2015 16:59:19 -0500 Subject: [PATCH] Update to Swift 1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - countElements() renamed to count() Via release notes - "The notions of guaranteed conversion and “forced failable” conversion are now separated into two operators. Forced failable conversion now uses the as! operator. The ! makes it clear to readers of code that the cast may fail and produce a runtime error. The “as” operator remains for upcasts (e.g. “someDerivedValue as Base”) and type annotations (“0 as Int8”) which are guaranteed to never fail." - "The implicit conversions from bridged Objective-C classes (NSString/NSArray/NSDictionary) to their corresponding Swift value types (String/Array/Dictionary) have been removed, making the Swift type system simpler and more predictable." - "The @autoclosure attribute is now an attribute on a parameter, not an attribute on the parameter’s type." --- SwiftShell/Command.swift | 4 ++-- SwiftShell/FileHandle.swift | 6 +++--- SwiftShell/String.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SwiftShell/Command.swift b/SwiftShell/Command.swift index 844c373..ca3a0a5 100644 --- a/SwiftShell/Command.swift +++ b/SwiftShell/Command.swift @@ -29,7 +29,7 @@ left side as standard input. Warning: is only meant to be used with the "run" command, but could also unintentionally catch other uses of "ReadableStreamType |> ReadableStreamType", though that statement doesn't make any sense. */ -public func |> (lhs: ReadableStreamType, rhs: @autoclosure () -> ReadableStreamType) -> ReadableStreamType { +public func |> (lhs: ReadableStreamType, @autoclosure rhs: () -> ReadableStreamType) -> ReadableStreamType { assert(_nextinput_ == nil) _nextinput_ = lhs let result = rhs() @@ -49,7 +49,7 @@ public func run (shellcommand: String) -> ReadableStreamType { let task = newtask(shellcommand) if let input = _nextinput_ { - task.standardInput = input as FileHandle + task.standardInput = input as! FileHandle _nextinput_ = nil } else { // avoids implicit reading of the main script's standardInput diff --git a/SwiftShell/FileHandle.swift b/SwiftShell/FileHandle.swift index fdf372c..3b19475 100644 --- a/SwiftShell/FileHandle.swift +++ b/SwiftShell/FileHandle.swift @@ -19,7 +19,7 @@ extension FileHandle: ReadableStreamType { return nil } else { if let result = NSString(data: data, encoding: streamencoding) { - return result + return result as String } else { printErrorAndExit("Fatal error - could not read stream.") } @@ -29,7 +29,7 @@ extension FileHandle: ReadableStreamType { public func read () -> String { let data: NSData = self.readDataToEndOfFile() if let result = NSString(data: data, encoding: streamencoding) { - return result + return result as String } else { printErrorAndExit("Fatal error - could not read stream.") } @@ -114,7 +114,7 @@ public func open (forWriting path: String, overwrite: Bool = false) -> Writeable } -public let environment = NSProcessInfo.processInfo().environment as [String: String] +public let environment = NSProcessInfo.processInfo().environment as! [String: String] public let standardinput = FileHandle.fileHandleWithStandardInput() as ReadableStreamType public let standardoutput = FileHandle.fileHandleWithStandardOutput() as WriteableStreamType public let standarderror = FileHandle.fileHandleWithStandardError() as WriteableStreamType diff --git a/SwiftShell/String.swift b/SwiftShell/String.swift index 1d0a184..1c47f5b 100644 --- a/SwiftShell/String.swift +++ b/SwiftShell/String.swift @@ -33,7 +33,7 @@ extension String { } public func countOccurrencesOf (substring: String) -> Int { - return self.findAll(substring) |> toArray |> countElements + return self.findAll(substring) |> toArray |> count } /** A lazy sequence of the ranges of `findstring` in this string. */