Skip to the content.

SwifterSwift 到 PTools 的迁移指南

适用版本:PTools 5.23.0,最低 iOS 17,Swift 6。

迁移原则

常用替换

旧:

array.filterDuplicates { $0.id }

新:

array.removingDuplicates { $0.id }

旧:

view.addSubviews([titleLabel, imageView])
view.removeSubviews()

新:

view.addSubviews(titleLabel, imageView)
view.removeAllSubviews()

旧:

dictionary.setValue(keys: ["user", "profile", "name"], newValue: "Jax")

新:

dictionary.setValue("Jax", at: ["user", "profile", "name"])

旧:

url.queryParameters

新:

url.queryValue(for: "page")
url.appendingQueryParameters(["page": "2"])

明确不迁移的能力

不加入 unsafeString、可选运算符、随机删除、frame sugar、标准库已有的 all/any 包装器和 GCD 并行 helper。Swift 6 并发场景使用 TaskGroup、async let、actor 或 AsyncSequence。

兼容说明

filterDuplicates、handleFilter、allKeys、allValues 和 asJsonStr 等旧 PTools 方法仍保留。allKeys/allValues 不再隐式打乱顺序;需要随机顺序时显式调用 shuffledKeys() / shuffledValues()。