I tried this:
var ss: [S] = NSMutableArray<S>(capacity: 0)
Compiler says: Cannot specialize non-generic type 'NSMutableArray'
Why?
NSArray
and NSMutableArray
are Objective C types, and do not support generics. You can instantiate as swift's native array type:
var settings = [Setting]()
which also can be written as
var settings = Array<Setting>()
Thanks to type inference, you don't have to specify the type, but if you like this are the complete versions:
var settings: [Setting] = [Setting]()
var settings: Array<Setting> = Array<Setting>()
Note that [Setting]
and Array<Setting>
are interchangeable, meaning they define the same object type, so you can use whichever you like more.
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