How to quickly assign a value to a similar variable name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.