initialization - Initialize property of type immutable dictionary in Swift init() -


i initialize immutable dictionary calculating values in init(). have:

class myclass {     var images: [string: uiimage]      func init() {         images = [:]         // ... loop on strings             // ... calculate image             images[string] = image     } } 

is there way define property let instead of var semantics. convenient , seem appropriate content won't changed after object has been initialized. (if change var let receive error assignment inside loop: "immutable value 'self.images' may not assigned to".)

make additional variable in init , assign once images:

class myclass {     let images: [string: uiimage]      func init() {         var tempimages = [string: uiimage]()         // ... loop on strings             // ... calculate image             tempimages[string] = image          // assign tempimages images         images = tempimages     } } 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -