Skip to content

Commit 5b16f0e

Browse files
author
Itai Ferber
committed
Correct URL bridging and exposure on Linux
(Truly correct bridging to be integrated with #555)
1 parent ff5eac7 commit 5b16f0e

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

Foundation/NSUserDefaults.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,10 @@ open class UserDefaults: NSObject {
227227
return
228228
}
229229
#else
230-
if let urlPath = url.path {
231-
//FIXME: stringByAbbreviatingWithTildeInPath isn't implemented in SwiftFoundation
232-
//TODO: use stringByAbbreviatingWithTildeInPath when it is
233-
setObject(urlPath._nsObject, forKey: defaultName)
234-
return
235-
}
230+
//FIXME: stringByAbbreviatingWithTildeInPath isn't implemented in SwiftFoundation
231+
//TODO: use stringByAbbreviatingWithTildeInPath when it is
232+
setObject(url.path._nsObject, forKey: defaultName)
233+
return
236234
#endif
237235
let data = NSKeyedArchiver.archivedData(withRootObject: url._nsObject)
238236
setObject(data._nsObject, forKey: defaultName)

Foundation/URL.swift

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public struct URL : ReferenceConvertible, Equatable {
752752
return self
753753
}
754754

755-
if let result = _url.deletingLastPathComponent.map({ URL(reference: $0 as NSURL) }) {
755+
if let result = _url.deletingLastPathComponent {
756756
return result
757757
} else {
758758
return self
@@ -785,7 +785,7 @@ public struct URL : ReferenceConvertible, Equatable {
785785
return self
786786
}
787787

788-
if let result = _url.deletingPathExtension.map({ URL(reference: $0 as NSURL) }) {
788+
if let result = _url.deletingPathExtension {
789789
return result
790790
} else {
791791
return self
@@ -837,7 +837,7 @@ public struct URL : ReferenceConvertible, Equatable {
837837
/// Returns a `URL` with any instances of ".." or "." removed from its path.
838838
public var standardized : URL {
839839
// The NSURL API can only return nil in case of file reference URL, which we should not be
840-
if let result = _url.standardized.map({ URL(reference: $0 as NSURL) }) {
840+
if let result = _url.standardized {
841841
return result
842842
} else {
843843
return self
@@ -856,7 +856,7 @@ public struct URL : ReferenceConvertible, Equatable {
856856
/// If the `isFileURL` is false, this method returns `self`.
857857
public var standardizedFileURL : URL {
858858
// NSURL should not return nil here unless this is a file reference URL, which should be impossible
859-
if let result = _url.standardizingPath.map({ URL(reference: $0 as NSURL) }) {
859+
if let result = _url.standardizingPath {
860860
return result
861861
} else {
862862
return self
@@ -868,7 +868,7 @@ public struct URL : ReferenceConvertible, Equatable {
868868
/// If the `isFileURL` is false, this method returns `self`.
869869
public func resolvingSymlinksInPath() -> URL {
870870
// NSURL should not return nil here unless this is a file reference URL, which should be impossible
871-
if let result = _url.resolvingSymlinksInPath.map({ URL(reference: $0 as NSURL) }) {
871+
if let result = _url.resolvingSymlinksInPath {
872872
return result
873873
} else {
874874
return self
@@ -927,26 +927,6 @@ public struct URL : ReferenceConvertible, Equatable {
927927
_url.removeCachedResourceValue(forKey: key)
928928
}
929929

930-
@available(*, unavailable, message: "Use struct URLResourceValues and URL.setResourceValues(_:) instead")
931-
public func setResourceValue(_ value: AnyObject?, forKey key: URLResourceKey) throws {
932-
fatalError()
933-
}
934-
935-
@available(*, unavailable, message: "Use struct URLResourceValues and URL.setResourceValues(_:) instead")
936-
public func setResourceValues(_ keyedValues: [URLResourceKey : AnyObject]) throws {
937-
fatalError()
938-
}
939-
940-
@available(*, unavailable, message: "Use struct URLResourceValues and URL.resourceValues(forKeys:) instead")
941-
public func resourceValues(forKeys keys: [URLResourceKey]) throws -> [URLResourceKey : AnyObject] {
942-
fatalError()
943-
}
944-
945-
@available(*, unavailable, message: "Use struct URLResourceValues and URL.setResourceValues(_:) instead")
946-
public func getResourceValue(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey key: URLResourceKey) throws {
947-
fatalError()
948-
}
949-
950930
// MARK: - Bridging Support
951931

952932
/// We must not store an NSURL without running it through this function. This makes sure that we do not hold a file reference URL, which changes the nullability of many NSURL functions.
@@ -968,15 +948,15 @@ public struct URL : ReferenceConvertible, Equatable {
968948
}
969949
}
970950

971-
extension URL : _ObjectiveCBridgeable {
951+
extension URL {
972952
@_semantics("convertToObjectiveC")
973953
public func _bridgeToObjectiveC() -> NSURL {
974954
return _url
975955
}
976956

977957
public static func _forceBridgeFromObjectiveC(_ source: NSURL, result: inout URL?) {
978958
if !_conditionallyBridgeFromObjectiveC(source, result: &result) {
979-
fatalError("Unable to bridge \(_ObjectiveCType.self) to \(self)")
959+
fatalError("Unable to bridge \(NSURL.self) to \(self)")
980960
}
981961
}
982962

@@ -1002,14 +982,6 @@ extension URL : CustomStringConvertible, CustomDebugStringConvertible {
1002982
}
1003983
}
1004984

1005-
extension NSURL : _HasCustomAnyHashableRepresentation {
1006-
// Must be @nonobjc to avoid infinite recursion during bridging.
1007-
@nonobjc
1008-
public func _toCustomAnyHashable() -> AnyHashable? {
1009-
return AnyHashable(self as URL)
1010-
}
1011-
}
1012-
1013985
extension URL : CustomPlaygroundQuickLookable {
1014986
public var customPlaygroundQuickLook: PlaygroundQuickLook {
1015987
return .url(absoluteString)

0 commit comments

Comments
 (0)