Skip to content

Commit d9da556

Browse files
authored
Merge pull request #1141 from stephencelis/nsurl-value
Value conformance for NSURL
2 parents 47ba31b + ee905fe commit d9da556

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Sources/SQLite/Foundation.swift

+16
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,19 @@ extension UUID: Value {
8484
}
8585

8686
}
87+
88+
extension URL: Value {
89+
90+
public static var declaredDatatype: String {
91+
String.declaredDatatype
92+
}
93+
94+
public static func fromDatatypeValue(_ stringValue: String) -> URL {
95+
URL(string: stringValue)!
96+
}
97+
98+
public var datatypeValue: String {
99+
absoluteString
100+
}
101+
102+
}

Tests/SQLiteTests/FoundationTests.swift

+11
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ class FoundationTests: XCTestCase {
2626
XCTAssertEqual(UUID(uuidString: "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3"), uuid)
2727
}
2828

29+
func testURLFromString() {
30+
let string = "http://foo.com"
31+
let url = URL.fromDatatypeValue(string)
32+
XCTAssertEqual(URL(string: string), url)
33+
}
34+
35+
func testStringFromURL() {
36+
let url = URL(string: "http://foo.com")!
37+
let string = url.datatypeValue
38+
XCTAssertEqual("http://foo.com", string)
39+
}
2940
}

0 commit comments

Comments
 (0)