In the Landmarks tutorial for SwuiftUI by Apple, is there some reason why the id property of the Landmarks struct is a var and not a let?
import SwiftUI
import CoreLocation
struct Landmark: Hashable, Codable, Identifiable {
var id: Int
// ...
}
Apparently not. You can safely turn the id into a let and all will work fine.
In fact, the Identifiable
protocol has no conflict there. It only requires id
to be gettable. It says nothing about settable:
public protocol Identifiable {
/// A type representing the stable identity of the entity associated with `self`.
associatedtype ID : Hashable
/// The stable identity of the entity associated with `self`.
var id: Self.ID { get }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With