Skip to content

Commit f0e28c3

Browse files
committed
Add implementation for NSURL copy()
1 parent 53a78d7 commit f0e28c3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Foundation/NSURL.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
8181
}
8282

8383
public func copyWithZone(_ zone: NSZone) -> AnyObject {
84-
NSUnimplemented()
84+
return self
8585
}
8686

8787
static public func supportsSecureCoding() -> Bool {
@@ -587,7 +587,7 @@ public class NSURLQueryItem : NSObject, NSSecureCoding, NSCopying {
587587
}
588588

589589
public func copyWithZone(_ zone: NSZone) -> AnyObject {
590-
NSUnimplemented()
590+
return self
591591
}
592592

593593
public static func supportsSecureCoding() -> Bool {

TestFoundation/TestNSURL.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class TestNSURL : XCTestCase {
6060
// TODO: these tests fail on linux, more investigation is needed
6161
("test_fileURLWithPath", test_fileURLWithPath),
6262
("test_fileURLWithPath_isDirectory", test_fileURLWithPath_isDirectory),
63-
("test_URLByResolvingSymlinksInPath", test_URLByResolvingSymlinksInPath)
63+
("test_URLByResolvingSymlinksInPath", test_URLByResolvingSymlinksInPath),
64+
("test_copy", test_copy)
6465
]
6566
}
6667

@@ -417,6 +418,16 @@ class TestNSURL : XCTestCase {
417418
XCTAssertEqual(result, "file:///tmp/")
418419
}
419420
}
421+
422+
func test_copy() {
423+
let url = NSURL(string: "https://www.swift.org")
424+
let urlCopy = url!.copy() as! NSURL
425+
XCTAssertTrue(url === urlCopy)
426+
427+
let queryItem = NSURLQueryItem(name: "id", value: "23")
428+
let queryItemCopy = queryItem.copy() as! NSURLQueryItem
429+
XCTAssertTrue(queryItem === queryItemCopy)
430+
}
420431
}
421432

422433
class TestNSURLComponents : XCTestCase {

0 commit comments

Comments
 (0)