替代的是append(path:directoryHint:)
美元.
如果您使用Xcode的代码完成功能,您可以清楚地看到这一点.键入类似以下内容:
someUrl.append
而Xcode则显示了可能的匹配列表.它将显示已弃用的方法,并提到替换方法.
另一种 Select 是在代码中右击appendPathComponent
的用法,然后 Select "跳转到定义".这将把您带到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的开发人员文档窗口没有显示替代版本.