NSNumber is a subclass of Nsvalue, the former can only wrap numbers, the latter may wrap any value. Nsarray, Nsdictionary can only store OC objects and cannot store structures. Therefore, if you want to put the structure in Nsarray, nsdictionary, can curve the salvation, the structure is packaged into OC objects, and then put in Nsarray, Nsdictionary and other sets of classes.
voidvalue () {Cgpoint point= Cgpointmake (Ten,Ten); //wrapping a struct variable as an objectNsvalue *value =[Nsvalue Valuewithpoint:point]; Nsmutablearray*array =[Nsmutablearray array]; //Add Value[Array addobject:value]; //Take out the value that was put inNsvalue *value1 =[Array lastobject]; Cgpoint point1=[value1 Pointvalue]; BOOL result=Cgpointequaltopoint (point1, point); NSLog (@"result=%i", result);} typedefstruct { intYear ; intmonth; intDay ;} Date;voidvalue2 () {Date Date= { -,4,7}; //void * represents any pointer//This is going to be the address of the struct &date//generate a corresponding type description string based on struct type Char*type =@encode (Date); Nsvalue*value = [Nsvalue value:&date Withobjctype:type]; //To define a struct-body variableDate date1; //Remove the packaged structure[Value getvalue:&Date1]; //[value objctype]; Remove type description stringNSLog (@"year=%i, month=%i, day=%i", Date1.year, Date1.month, date1.day);}
Objective-c:foundation Framework-Common class-nsvalue