.identified(by:) 已弃用?
.identified(by:) Deprecated?
此代码之前在 Xcode11 Beta 4 中运行。在最新的 Beta 5 中,我在“.identified(by:)”代码块中遇到错误。
我查看了 XCode11 Beta 5 的发行说明,但没有看到任何对 .identified(by:) 被弃用的引用。
import SwiftUI
import Combine
struct Popups: Decodable {
let name, truckRating, upcomingLocation, cuisine, truckImage, region,
city, state, currentLocation, numberOfRatings, truckExpense : String
}
class NetworkManager: ObservableObject {
var objectWillChange = PassthroughSubject<NetworkManager, Never>()
var popups = [Popups]() {
didSet {
objectWillChange.send(self)
}
}
init() {
guard let url = URL(string:
"https://www.example.com/db.json") else { return }
URLSession.shared.dataTask(with: url) { (data, _, _) in
guard let data = data else { return }
let popups = try! JSONDecoder().decode([Popups].self, from: data)
DispatchQueue.main.async {
self.popups = popups
}
print("Completed fetching JSON")
}.resume()
}
}
struct ItemsView: View {
@State var networkManager = NetworkManager()
var body: some View {
NavigationView {
List (
networkManager.popups.identified(by: \.name)
) { popup in
ItemsRowView(popup: popup)
}.navigationBarTitle(Text("Pop Ups"))
}
}
}
错误消息指出 "Value of type '[Popups]' has no member 'identified'"
.identified(by:)
已弃用。正如您正确指出的那样,Xcode beta 的发行说明中没有注明这一点,但在 iOS beta 的发行说明中没有注明,这就是您找不到它的原因。这有点令人困惑,因为与 SwiftUI 相关的更改分散在 iOS 13 beta、Xcode 11 beta 和 macOS Catalina beta 的发行说明中。
The identified(by:) method on the Collection protocol is deprecated in
favor of dedicated init(:id:selection:rowContent:) and
init(:id:content:) initializers. (52976883, 52029393)
但是 identified(by:)
弃用发生在 beta 4 中,因此以下内容也适用:
SwiftUI APIs deprecated in previous betas are now removed. (52587863)
这个问题在某种程度上与 重复,但发行说明中提到弃用的地方令人困惑,值得将其作为一个单独的问题。
此代码之前在 Xcode11 Beta 4 中运行。在最新的 Beta 5 中,我在“.identified(by:)”代码块中遇到错误。
我查看了 XCode11 Beta 5 的发行说明,但没有看到任何对 .identified(by:) 被弃用的引用。
import SwiftUI
import Combine
struct Popups: Decodable {
let name, truckRating, upcomingLocation, cuisine, truckImage, region,
city, state, currentLocation, numberOfRatings, truckExpense : String
}
class NetworkManager: ObservableObject {
var objectWillChange = PassthroughSubject<NetworkManager, Never>()
var popups = [Popups]() {
didSet {
objectWillChange.send(self)
}
}
init() {
guard let url = URL(string:
"https://www.example.com/db.json") else { return }
URLSession.shared.dataTask(with: url) { (data, _, _) in
guard let data = data else { return }
let popups = try! JSONDecoder().decode([Popups].self, from: data)
DispatchQueue.main.async {
self.popups = popups
}
print("Completed fetching JSON")
}.resume()
}
}
struct ItemsView: View {
@State var networkManager = NetworkManager()
var body: some View {
NavigationView {
List (
networkManager.popups.identified(by: \.name)
) { popup in
ItemsRowView(popup: popup)
}.navigationBarTitle(Text("Pop Ups"))
}
}
}
错误消息指出 "Value of type '[Popups]' has no member 'identified'"
.identified(by:)
已弃用。正如您正确指出的那样,Xcode beta 的发行说明中没有注明这一点,但在 iOS beta 的发行说明中没有注明,这就是您找不到它的原因。这有点令人困惑,因为与 SwiftUI 相关的更改分散在 iOS 13 beta、Xcode 11 beta 和 macOS Catalina beta 的发行说明中。
The identified(by:) method on the Collection protocol is deprecated in favor of dedicated init(:id:selection:rowContent:) and init(:id:content:) initializers. (52976883, 52029393)
但是 identified(by:)
弃用发生在 beta 4 中,因此以下内容也适用:
SwiftUI APIs deprecated in previous betas are now removed. (52587863)
这个问题在某种程度上与