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:
Kare Morstol
2015-09-08 23:44:09 +02:00
parent f41f243630
commit a222c4d15a
2 changed files with 10 additions and 1 deletions
+4
View File
@@ -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)
}
+6 -1
View File
@@ -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"))
}
}