Dark Horse Programmer--foundation Study notes (ii)

Source: Internet
Author: User

——-Android Training, Java training, iOS training, look forward to communicating with you! ———-
"1" The last note to write nsstring, in fact, the development of commonly used is the Nsmutablestring class string, the literal meaning is that the latter is variable, and the former is immutable, in fact, this is their essential difference. The following is a detailed description in the code:

nsstring  * S1 = @ "yeahming" ; //Create immutable string  //here does not provide any method that can change s, but there is a and [SS appendformat:@ "Best"]; similar, but qualitative difference method  nsstring  *s2 = [S1 stringbyappendingstring:@ "fan" ];//but the above method is required to return a value, that is, he needs to create another object, rather than the original S1, but the value of S1 to get over the stitching "fan" and then put in S2   nsmutablestring  *ss = [nsmutablestring  Stringwithformat:@ "Yeahmingfan" ]; //create a mutable string that cannot be created in the above way  [SS Appendformat:@ "best" ]; The string created by the //nsmutablestring class is a  that provides a class method that can be changed. nslog  (@ "%@" , ss);  

The result of the above operation is:

"2," Let's talk about Nsarray.

Nsarray*STR0 = [Nsarrayarraywithobjects:@"Jim", @"Man",@"very",Nil];//Basic Creation Method    Nsarray*STR1 = @[@"Jim", @"Man",@"very"];//Simple Create mode    Nsmutablearray*STR = [Nsmutablearrayarraywithobjects:@"Jim", @"Man",@"very",Nil];//@[@ "Jim" @ "10 years old" @ "Gender: Male", nil];//mutable array is not created in the simple way above[Str addobject:@"single"];//variable array can change the visual monetization     for(IDObj in str) {NSLog(@"%@", obj); }//This is the first fast way to iterate through an array[Str enumerateobjectsusingblock:^ (IDobj, Nsuinteger idx,BOOL*stop) {NSLog(@"%ld-%@", idx,obj); }];//This is the second way of fast traversal, and it's more useful    NSLog(@"str1=%@\nstr=%@", STR1,STR);NSLog(@"str[1]=%@", str[1]);//access the corresponding location of the array, which can be used directly, he will automatically convert str[1] to [str objectatindex:1]Nsuinteger count = str. Count;//Calculate the length of the array, that is, the number of elements

"3" where nsset only a few points of attention, because the usage and Nsarray usage similar, but: Nsarray objects in order, and Nsset is unordered, which leads to the latter may be less appropriate methods
"4" The next is the use of more commonly used nsdictionary, in fact, and the above two is also a set, but he is a set with key, through key can be found exactly the corresponding object, in the following code to explain:

  nsdictionary*dic = @{@"Name":@"Yeahming", @"Sex":@"Man"};///Immutable dictionary collection The simplest and most straightforward way to create    NSLog(@"%ld"Dic. Count);The length of the dictionary class, which is a pair of pairs of calculated    NSLog(@"%@", DIC); [DiC enumeratekeysandobjectsusingblock:^ (IDKeyIDObjBOOL*stop) {NSLog(@"%@=%@", key, obj); }];the same simple traversal method as the previous collections    nsmutabledictionary*dic1= [nsmutabledictionarydictionarywithobject:@"Jack"forkey:@"Englishname"]; [Dic1 setobject:@"China"forkey:@"Country"];//Add element[Dic1 setobject:@"Rose"forkey:@"Name"];//If you add a key before it, it will overwrite the element corresponding to the previous key, overwriting the name of the previous name key

Dark Horse Programmer--foundation Study notes (ii)

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.