I would like to initialize an immutable dictionary by calculating its values in init()
. I currently have:
class MyClass {
var images: [String: UIImage]
func init() {
images = [:]
for // ... loop over strings
// ... calculate image
images[string] = image
}
}
Is there any way to define this property with let
instead of var
semantics. This would be convenient and seem appropriate as its content won't be changed after the object has been initialized. (If I just change this var
into let
I currently receive this error for the assignment inside the loop: "immutable value 'self.images' may not be assigned to".)