The fast-acting equivalent of arrayWIthObjects?
This is in Obj C:
NSArray *arr = [NSArray arrayWithObjects:kLMEnglish,nil];
Can anyone tell me a quick equivalent to this line of code.
+3
Labinot Bajrami
source
to share
3 answers
Try this code:
var myVar1: Int = 50
var myVar2: Int = 50
var array: NSArray? = NSArray(objects: myVar1,myVar2)
+10
Utsav Parikh
source
to share
How about this?
let arr = [kLMEnglish]
In ObjC, you can also write:
NSArray *arr = @[kLMEnglish];
+12
sergio
source
to share
In quick play, you can use an array like this
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 the beginning of the line starts with var , that means a variable and allows the contents of the array to change in the future.
If the beginning of the line starts with let , which means a constant and means that the contents cannot be changed in the future.
+1
user3182143
source
to share