Dictionary, Set Exercises

Source: Internet
Author: User
Tags allkeys
# Import "viewcontroller. H "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; nsarray * array1 = [nsarray arraywithobjects: @" wangwei ", @ "wangwangwei", nil]; nsarray * array2 = [nsarray arraywithobjects: @ "zhangsan", @ "zhangzhang", nil]; nsdictionary * dicl = [nsdictionary alloc] Branch: array1, @ "Wang", array2, @ "Zhang", nil]; // obtain the number of elements in the dictionary. nsuinteger COUNT = dicl. count; nslog (@ "count: % lD", count); nsdictionary * dicl1 = [nsdictionary dictionarywithobject: array1 forkey: @ "Wang"]; // create a dictionary to initialize an element // obtain all keys in the dictionary nsarray * allkeys = [dicl allkeys]; nslog (@ "% @", allkeys ); // obtain all value nsarray * allvalue = [dicl allvalues]; nslog (@ "% @", allvalue); // obtain value nsarray * array3 = [dicl objectforkey through key: @ "Wang"]; nslog (@ "% @", array3); nsarray * array4 = [dicl objectforkey: @ "Zhang"]; nslog (@ "------------ % @ ---------------", array4); nsdictionary * dicl2 ={ @ "Wang": array1, @ "Zhang": array2 }; // optimized nslog (@ "xxxxxxxxxxxxxxxx % @ xxxxxxxxxxxx", dicl2); nsarray * array5 = dicl2 [@ "Zhang"]; // obtain value nslog (@ "array5 = % @", dicl2) through key;}-(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} @ end

Set Exercises

# Import "viewcontroller. H "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; // do any additional set nsset up after loading the view, typically from a nib. nsstring * S1 [email protected] "zhangsan"; nsstring * S2 [email protected] "wangwei"; // create an nsset object nsset * set1 = [[nsset alloc] initwithobjects: S1, s2, nil]; nsset * set2 = [nsset setwithobjects: S1, S2, nil]; // Retrieves all elements in the array, save to the set object // nsset * set3 = [nsset setwitharray: <# (nsarray *) #>]; // nsset is converted to an array nsarray * array1 = [set1 allobjects]; // return the number of elements nsuinteger COUNT = [set1 count]; // set1.count; // obtain an element nsstring * S3 = [set1 anyobject] randomly from the container; // The nsset object nsstring * STR [email protected] "Jack"; nsarray * array2 = [nsarray arraywithobjects: Str, STR, nil]; nslog (@ "% @", array2); nsset * set4 = [nsset setwithobjects: Str, STR, nil]; nslog (@ "% @", set4); return ;} -(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} @ end

 

Dictionary, Set Exercises

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.