URL appendPathComponent(_:) 已弃用?

问题描述 投票:0回答:1

官方文档说它已被弃用:https://developer.apple.com/documentation/foundation/url/1780397-appendpathcomponent

什么是替代品?

swift url
1个回答
1
投票

替换为

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

© www.soinside.com 2019 - 2024. All rights reserved.