OC----Dictionary collection iOS learning-----Crushing Knowledge points Summary

Source: Internet
Author: User

the creation of an instance method Nsdictionary*wukong = [[Nsdictionary alloc] Initwithobjectsandkeys:@"Wu Empty",@"name",@"male",@"Gender",@" -",@" Age", nil]; NSLog (@"%@", Wukong); //Convenience Builder CreationNsdictionary *wuneng = [nsdictionary dictionarywithobjects:[nsarray arraywithobjects:@"Wu can",@"male",@" -", nil] Forkeys:[nsarray arraywithobjects:@"name",@"Gender",@" Age", Nil]]; NSLog (@"Wuneng =%@", Wuneng);
//get dictionary at all keyNsarray *allkey =[Wuneng AllKeys]; NSLog (@"Allkey =%@", Allkey); //gets all the value in the dictionaryNsarray *allvalue =[Wuneng allvalues]; NSLog (@"Allvalue =%@", Allvalue); //query the corresponding value by keyNSString *name = [Wukong valueforkey:@"name"]; NSLog (@"name =%@", name); NSString*gender = [Wukong valueforkey:@"Gender"]; NSLog (@"gender =%@", gender); //use Valueforkey and Objectforkey to take value from a dictionary based on keyNSString *age = [Wukong objectforkey:@" Age"]; NSLog (@"%@", age);

#pragma mark-nsmutabledictionary

Nsmutabledictionary *mingren = [Nsmutabledictionary Dictionarywithobjectsandkeys:@"Whirlpool Naruto",@"name",@"male",@"Gender",@" +",@" Age", nil]; //to add a key-value pair[Mingren SetValue:@"Eat ramen"Forkey:@"Hobby"]; [Mingren SetValue:@"Wood Leaf"Forkey:@"Address"]; //Change[Mingren SetValue:@"Eat steamed buns"Forkey:@"Hobby"]; //Setvalue:forkey: And Object:forkey: When the key is present, it is the value of the key corresponding to the change, and when the key does not exist, it is added a pair of Jianzhi[Mingren setvalue:nil Forkey:@"Hobbby"];//    //[Mingren setvalue:nil forkey:@ "Address"]; //the corresponding object in the method cannot be empty, or it will crash//[Mingren setvalue:[nsnull null] forkey:@ "address"; //use Nsnull If you want to give the empty value I all 、、、//[Mingren setobject:[nsnull null] forkey:@ "Address"]//Delete[Mingren Removeobjectforkey:@"Address"]; //Quick enumeration of the for in Fast enumeration dictionary, in front is the type of key, in followed by the Dictionary object (instance)     for(NSString *keyinchMingren) {NSLog (@"key =%@, value =%@", Key, [Mingren Valueforkey:key]); }

#pragma mark-nsset &nsmutableset

//Create a Nsset objectNSNumber *number1 = [NSNumber numberwithint:3]; NSNumber*number2 = [NSNumber numberwithint:Ten]; NSNumber*number3 = [NSNumber numberwithint: -]; NSNumber*number4 = [NSNumber numberwithint: -]; Nsset*Set=[[Nsset alloc] Initwithobjects:number1, Number2, Number3,number1, Number4, nil]; NSLog (@"----%@",Set); NSLog (@"%ld", [SetCount]);//the number inside the collectionNSLog (@"===%@", [SetAnyobject]);//Take an element out of the collection        if([SetContainsobject:number1]) {//whether the collection contains an elementNSLog (@"there's number1 in the collection."); } Else{NSLog (@"This object is not in the collection"); }        //Create a Nsmutbleset objectNsmutableset *mutableset = [Nsmutableset setwithobjects:@3, @4, @5, @9, @ -, nil];//literal quantityNSLog (@"%@", [[SetAnyobject]class]); NSLog (@"==%@", [Number1class]); //Add[Mutableset addobject:@ the]; //Delete Element[Mutableset removeobject:@3]; NSLog (@"-=-=%@", Mutableset); Nscountedset*countedset =[Nscountedset setwithobjects:number1, Number2, Number3, Number3, Number4, number2, nil]; NSLog (@"%@", Countedset); NSLog (@"the number of Number1 is:%ld", [Countedset Countforobject:number1]);//gets the number of times an object repeats in Nscountedset//Fast enumeration of Nsset by using Forin     for(NSNumber *numberinch Set) {NSLog (@"----%@", number); }        //reading a string from a fileNserror *error =Nil; NSString*txtstring = [[NSString alloc] Initwithcontentsoffile:@"/users/lanou3g/desktop/test.txt"Encoding:nsutf8stringencoding error:&ERROR]; NSLog (@"%@", txtstring);

OC----Dictionary collection iOS learning-----Crushing Knowledge points Summary

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.