Reputation: 7437
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
// ...
}
Upvotes: 4
Views: 799
Reputation: 40509
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 }
}
Upvotes: 4