```swift
let string = "https://www.baidu.com"
let newString = string.appendingPathComponent("temp.mp3")
print(newString)
// result: "https:/www.baidu.com/temp.mp3" It is a bad url string
// If I convert it to a url
let url = URL(string: string)
let newUrl = url?.appendingPathComponent("temp.mp3")
print(newUrl)
// result: "https://www.baidu.com/temp.mp3" It is correct
````
Hi @fanglinwei ,
Thanks for raising this issue. Upon checking this, seems like this is the expected behavior when we call .appendingPathComponent(_:) on a string. As per NSString documentation,
Note that this method only works with file paths (not, for example, string representations of URLs).
https://developer.apple.com/documentation/foundation/nsstring/1417069-appendingpathcomponent
I've added the documentation notes here https://github.com/SwifterSwift/SwifterSwift/pull/709
@cHaLkdusT ,
Thank you for your answer so that we can clearly understand the correct use of this function.
Most helpful comment
Hi @fanglinwei ,
Thanks for raising this issue. Upon checking this, seems like this is the expected behavior when we call
.appendingPathComponent(_:)on a string. As per NSString documentation,https://developer.apple.com/documentation/foundation/nsstring/1417069-appendingpathcomponent