swift URL appendPathComponent(_:)是否已弃用?

zdwk9cvp  于 2023-02-28  发布在  Swift
关注(0)|答案(1)|浏览(185)
nuypyhwy

nuypyhwy1#

替换为append(path:directoryHint:)
如果你使用Xcode的代码完成功能,你可以清楚地看到这一点。

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的开发者文档窗口不显示替换。

相关问题