Skip to content

Commit 4c2dec5

Browse files
committed
Simplified URLComponents getters
1 parent 8ae20fa commit 4c2dec5

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Foundation/URLComponents.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
107107
/// The getter for this property removes any percent encoding this component may have (if the component allows percent encoding). Setting this property assumes the subcomponent or component string is not percent encoded and will add percent encoding (if the component allows percent encoding).
108108
public var path: String {
109109
get {
110-
guard let result = _handle.map({ $0.path }) else { return "" }
111-
return result
110+
return _handle.map { $0.path } ?? ""
112111
}
113112
set {
114113
_applyMutation { $0.path = newValue }
@@ -161,8 +160,7 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
161160
/// The getter for this property retains any percent encoding this component may have. Setting this properties assumes the component string is already correctly percent encoded. Attempting to set an incorrectly percent encoded string will cause a `fatalError`. Although ';' is a legal path character, it is recommended that it be percent-encoded for best compatibility with `URL` (`String.addingPercentEncoding(withAllowedCharacters:)` will percent-encode any ';' characters if you pass `CharacterSet.urlPathAllowed`).
162161
public var percentEncodedPath: String {
163162
get {
164-
guard let result = _handle.map({ $0.percentEncodedPath }) else { return "" }
165-
return result
163+
return _handle.map { $0.percentEncodedPath } ?? ""
166164
}
167165
set {
168166
_applyMutation { $0.percentEncodedPath = newValue }

0 commit comments

Comments
 (0)