官方文档表示这已经被弃用了:https://developer.apple.com/documentation/foundation/url/1780397-appendpathcomponent
什么是替代品?
append(path:directoryHint:)
。someUrl.append
并且Xcode将显示可能匹配的列表。它会显示已弃用的方法,并提及替代方案。
另一个选项是在代码中右键单击对appendPathComponent
的使用,并选择“跳转到定义”。这将带您进入Foundation.URL的接口文件,您将看到类似以下内容:/// Appends a path component to the URL.
///
/// - note: This function performs a file system operation to determine if the path component is a directory. If so, it will append a trailing `/`. If you know in advance that the path component is a directory or not, then use `func appendingPathComponent(_:isDirectory:)`.
/// - parameter pathComponent: The path component to add.
@available(macOS, introduced: 10.9, deprecated: 100000.0, message: "Use append(path:directoryHint:) instead")
@available(iOS, introduced: 7.0, deprecated: 100000.0, message: "Use append(path:directoryHint:) instead")
@available(tvOS, introduced: 9.0, deprecated: 100000.0, message: "Use append(path:directoryHint:) instead")
@available(watchOS, introduced: 2.0, deprecated: 100000.0, message: "Use append(path:directoryHint:) instead")
public mutating func appendPathComponent(_ pathComponent: String)
@available
表示替换内容。这就是 Xcode 显示替换的方式。不确定为什么在线文档和 Xcode 的开发者文档窗口没有显示替换。