Implement "NSURL / String" operator.
Overriding a standard operator for a completely different use case like this is not normally recommended, but I think it is warranted here. It's certainly a lot better than "URLByAppendingPathComponent".
This commit is contained in:
@@ -10,3 +10,7 @@ import Foundation
|
||||
/** The default NSFileManager */
|
||||
public let Files = NSFileManager.defaultManager()
|
||||
|
||||
/** Append file or directory url to directory url */
|
||||
public func / (leftpath: NSURL, rightpath: String) -> NSURL {
|
||||
return leftpath.URLByAppendingPathComponent(rightpath)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
import SwiftShell
|
||||
import XCTest
|
||||
|
||||
class Files_Tests: XCTestCase {
|
||||
class UrlAppendationOperator: XCTestCase {
|
||||
|
||||
func testUrlSlashString () {
|
||||
XCTAssertEqual( NSURL(fileURLWithPath: "dir") / "file.txt", NSURL(fileURLWithPath: "dir/file.txt"))
|
||||
XCTAssertEqual( NSURL(fileURLWithPath: "dir/") / "/file.txt", NSURL(fileURLWithPath: "dir/file.txt"))
|
||||
XCTAssertEqual( NSURL(string: "dir")! / "file.txt", NSURL(string: "dir/file.txt"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user