Update for Xcode 7 beta 6.

For some reason "NSURL.checkResourceIsReachable() throws" is gone and "checkResourceIsReachableAndReturnError(NSErrorPointer)" is back even though the documentation says otherwise. Methods of other Cocoa classes which take NSError pointers have been converted to throwing functions.
This commit is contained in:
Kare Morstol
2015-08-28 00:34:01 +02:00
parent 4aeb5d7daa
commit 3218fd4315
4 changed files with 22 additions and 13 deletions
+1 -1
View File
@@ -85,5 +85,5 @@ public func $ (shellcommand: String) -> String {
/** Turn a sequence into valid parameters for a shell command, properly quoted */
public func parameters <S : SequenceType> (sequence: S) -> String {
return " " + " ".join( sequence.map { "\"\($0)\"" } )
return " " + ( sequence.map { "\"\($0)\"" } ).joinWithSeparator(" ")
}
+13 -4
View File
@@ -71,16 +71,25 @@ extension FileHandle: WriteableStreamType {
exit(EXIT_FAILURE)
}
/** Run a function which takes a NSErrorPointer. If an NSError occurs, throw it, otherwise return result. */
func makeThrowable <T> (nserrorfunc: (NSErrorPointer) -> T) throws -> T {
var maybeerror: NSError?
let result = nserrorfunc(&maybeerror)
if let actualerror = maybeerror {
throw actualerror
}
return result
}
/** Open a file for reading, and exit if an error occurs. */
public func open (path: String) -> ReadableStreamType {
let url = toURLOrError(path)
do {
let filehandle = try FileHandle(forReadingFromURL: url)
return filehandle
return try FileHandle(forReadingFromURL: url)
} catch {
do {
try url.checkResourceIsReachable()
try makeThrowable(url.checkResourceIsReachableAndReturnError)
} catch {
printErrorAndExit(error)
}
@@ -107,7 +116,7 @@ public func open (forWriting path: String, overwrite: Bool = false) -> Writeable
return filehandle
} catch {
do {
try url.checkResourceIsReachable()
try makeThrowable(url.checkResourceIsReachableAndReturnError)
} catch {
printErrorAndExit(error)
}
+7 -7
View File
@@ -22,9 +22,9 @@ public func |> <T,U> (lhs: T, rhs: T -> U) -> U {
public func filter <S : SequenceType>
(includeElement: (S.Generator.Element) -> Bool)
(source: S)
-> LazySequence<FilterSequence<S>> {
-> LazyFilterSequence<S> {
return lazy(source).filter(includeElement)
return source.lazy.filter(includeElement)
}
/**
@@ -45,9 +45,9 @@ public func sorted <S : SequenceType>
public func map <S: SequenceType, T>
(transform: (S.Generator.Element) -> T)
(source: S)
-> LazySequence<MapSequence<S, T>> {
-> LazyMapSequence<S,T> {
return lazy(source).map(transform)
return source.lazy.map(transform)
}
/**
@@ -71,9 +71,9 @@ public func split (delimiter delimiter: String = "\n")(text: String) -> [String]
public func join <C : RangeReplaceableCollectionType, S : SequenceType where S.Generator.Element == C>
(separator: C)
(elements: S)
-> C {
-> JoinSequence<S> {
return join(separator, elements)
return elements.joinWithSeparator(separator)
}
/** Turn a sequence into an array. For use after the |> operator. */
@@ -85,7 +85,7 @@ public func toArray <S : SequenceType> (sequence: S) -> [S.Generator.Element] {
public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T>
(tobedropped: [T])
(sequence: S)
-> LazySequence<FilterSequence<S>> {
-> LazyFilterSequence<S> {
return sequence |> filter { !tobedropped.contains($0) }
}
+1 -1
View File
@@ -19,7 +19,7 @@ export DYLD_FRAMEWORK_PATH=$PROJECT_ROOT/build/Release/
# Be aware the “assert” command does not check standard error output or exit code.
assert "./print_arguments.swift 1 2" "[./print_arguments.swift, 1, 2]"
assert "./print_arguments.swift 1 2" "[\"./print_arguments.swift\", \"1\", \"2\"]"
assert_raises "./exitswhenopeningnon-existentfile.swift" 1
assert "cat onetwothree.txt | ./print_linenumbers.swift" "line 1: one\nline 2: two\nline 3: three"
assert "./stream_out.swift" " 3"