Reputation: 1399
This code was previously working in Xcode11 Beta 4. In the latest Beta 5 I'm getting an error on the ".identified(by:)" block of code.
I looked through the release notes on XCode11 Beta 5 but I didn't see any reference to .identified(by:) being deprecated.
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"))
}
}
}
The error message states "Value of type '[Popups]' has no member 'identified'"
Upvotes: 2
Views: 1064
Reputation: 1679
.identified(by:)
is deprecated. As you correctly stated, this is not noted in the release notes for Xcode beta, but in the release notes for iOS beta, which is why you couldn't find it. It's a little confusing because the changes relating to SwiftUI are scattered across the release notes for iOS 13 beta, Xcode 11 beta, and 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)
But the identified(by:)
deprecation happened in beta 4, so the following also applies:
SwiftUI APIs deprecated in previous betas are now removed. (52587863)
This question is sort of a duplicate of SwiftUI ForEach 'identified(by:)' is deprecated. Use ForEach(_:id:) or List(_:id:), but the confusion around where the deprecation is mentioned in the release notes merits keeping it as a separate question.
Upvotes: 1