What is the difference between initializing the nsmutabledictionary in the loop and initializing the nsmutabledictionary outside of the loop, given the two ways iOS gives Nsmutabledictionary a loop assignment? (Resolved)

Source: Internet
Author: User

nsmutablearray * arrayname = [nsmutablearrayarray];

nsmutablearray * array = [nsmutablearrayarray];

[Array removeallobjects];

for (int i =0; i< ; i++) {

nsstring * str = [nsstringstringwithformat:@ "name%i", I];

[Arraynameaddobject: str];

}


     // Way one In for in-loop initialization dictionary dict 10

for (int i =0; i< ; i++) {

nsmutabledictionary * dict = [nsmutabledictionarydictionary];

nsstring * value = [nsstringstringwithformat:@ "female%04i. JPG ", I];

nsstring * key = Arrayname[i];

[Dictsetobject: Value forkey: key];

[Arrayaddobject:d ICT];

}

NSLog(@ "%@*************", array);

// mode two initializes the dictionary dictoutside of the for loop, and then initializes the mutable dictionary outside of the loop, adding a key-value pair within the dictionary each time the loop is added, Assigns a dictionary of 10 key-value pairs to an array

nsmutablearray * array2 = [nsmutablearrayarray];

nsmutabledictionary * dict2 = [nsmutabledictionarydictionary];

for (int i =0; i< ; i++) {

nsstring * value = [nsstringstringwithformat:@ "female%04i. JPG ", I];

nsstring * key = Arrayname[i];

[Dict2setobject: Value forkey: key];

}

[Array2addobject:d Ict2];

NSLog (@ "%@____________", array2);

// The difference between the two can be clearly seen from the printed results

// because the dictionary is not understood very deeply: just think of him as a key-value pair, but he can actually save n Key pairs (if you initialize a mutable dictionary every time before setting a key-value pair for a mutable dictionary, there is only one key-value pair for each dictionary)



What is the difference between initializing the nsmutabledictionary in the loop and initializing the nsmutabledictionary outside of the loop, given the two ways iOS gives Nsmutabledictionary a loop assignment? What is the difference between initializing the nsmutabledictionary in the loop and initializing the nsmutabledictionary outside of the loop when iOS gives Nsmutabledictionary a loop assignment? (Resolved)


What is the difference between initializing the nsmutabledictionary in the loop and initializing the nsmutabledictionary outside of the loop, given the two ways iOS gives Nsmutabledictionary a loop assignment? (Resolved)

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.