URL的appendPathComponent(_:)是否已弃用?替代方案是什么?
URL的appendPathComponent(_:)方法替代方案
官方文档显示URL.appendPathComponent(_:)方法已被弃用,其替代方案是使用URL.appending(path:)实例方法。
示例对比
原弃用写法:
let baseURL = URL(string: "https://example.com")! let targetURL = baseURL.appendPathComponent("articles")
推荐替代写法:
let baseURL = URL(string: "https://example.com")! let targetURL = baseURL.appending(path: "articles")
appending(path:)方法完全继承了原方法的核心功能,能够安全地为URL追加路径组件,同时遵循苹果最新的API设计规范。
内容的提问来源于stack exchange,提问作者Hammerhead
相关产品推荐
相关产品推荐

