let url = URL(string: "https://example.com/foo/bar")! url.path // "/foo/bar" url.path.split(separator: "/") // ["foo", "bar"] url.path.split(separator: "/", omittingEmptySubsequences: false) // ["", "foo", "bar"] url.pathComponents // ["/", "foo", "bar"]
ドキュメントはこちら:
path
:URL
: https://developer.apple.com/documentation/foundation/url/1779812-path- 情報量が少ないので
NSURL
の方も見られたい
- 情報量が少ないので
NSURL
: https://developer.apple.com/documentation/foundation/nsurl/1408809-path
pathComponents
:split
: https://developer.apple.com/documentation/swift/string/2894564-split