This is in Obj C:
NSArray *arr = [NSArray arrayWithObjects:kLMEnglish,nil];
Can someone tell me the swift equivalent for this line of code.
What about this?
let arr = [kLMEnglish]
In ObjC you could also write:
NSArray *arr = @[kLMEnglish];
Try this code :
var myVar1: Int = 50
var myVar2: Int = 50
var array: NSArray? = NSArray(objects: myVar1,myVar2)
In swift you can use array blow like that
let array: NSArray = [kLMEnglish]
var array:NSArray! = [kLMEnglish]
var arrayMutable = [kLMEnglish] as NSArray
let arrayImmutable = [kLMEnglish] as NSArray
var array = [kLMEnglish]
// if it is String
var array: [String] = [kLMEnglish]
// if it is Integer
var array:[Int] = [kLMEnglish]
If beginning of the line begins with var, which means variable and allows the contents of the array to be changed in the future.
If beginning of the line begins with let, which means constant and means the contents can not be changed in the future.
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