Now there is a requirement that there are four variables in the controller that need to be conveniently assigned the same value, how to implement it?
{ Nsarray *_arr1; Nsarray *_arr2; Nsarray *_ARR3; Nsarray *_ARR4;}
I used the OBJECT-C runtime to solve the problem.
for (int i = 1; i < 5; i + +) { ///Get the variable, the first parameter is the owning class of the variable, the second argument is the variable name string, the string to be converted to C Ivar var = class_getinstancevariable ( [Self class], [[NSString stringwithformat:@ "_arr%d", I] utf8string]); Assign a value to a variable, the first parameter is the class object to which the variable belongs, the second parameter is the variable that needs to be assigned, the third parameter is the value assigned to Object_setivar (self, VAR, @[@ "A", @ "B"]); }
Print under
2015-04-26 14:56:19.362 runtime[23492:599694] arr1 = ( A, b) 2015-04-26 14:56:19.363 runtime[23492:599694] arr2 = ( A, b) 2015-04-26 14:56:19.363 runtime[23492:599694] Arr3 = ( A, b) 2015-04-26 14:56:19.363 runtime[ 23492:599694] Arr4 = ( A, b)
The assignment was successful!
How to quickly assign a value to a similar variable name