Special types of wrapper classes: arrays, structs (internal OC, custom), pointers
1 //2 //main.m3 //05-nsvalue4 //5 //Created by Ma C on 15/8/17.6 //Copyright (c) 2015 BJSXT. All rights reserved.7 //8 9 #import<Foundation/Foundation.h>Tentypedefstruct One { A Char*name; - intAge ; - Chargender; the }student; - - intMainintargcConst Char*argv[]) - { + @autoreleasepool - { + //nsvalue Test A //1. Pointers at intnum =Ten; - int*p = # -Nsvalue *value1 =[Nsvalue valuewithpointer:p]; - int*P2 = (int*) [value1 Pointervalue]; -NSLog (@"num =%d",*(p2)); - in //2. Arrays - intarr[5] = {1,2,3,4,5}; toNsvalue *value2 =[Nsvalue Valuewithpointer:arr]; + int*P3 = (int*) [value2 Pointervalue]; - for(intI=0; i<5; i++) the { *NSLog (@"%d", P3[i]); $ }Panax Notoginseng - //structure commonly used in 3.Foundation: Nsrange\nsrect\nssize\nspoint theNsrange range = Nsmakerange (0,5); +Nsvalue *value3 =[Nsvalue Valuewithrange:range]; ANsrange Range2 =[Value3 Rangevalue]; theNSLog (@"%@", Nsstringfromrange (Range2)); + -Nsrect rect = Nsmakerect (0,0, -, -); $Nsvalue *value4 =[Nsvalue Valuewithrect:rect]; $Nsrect Rect2 =[Value4 Rectvalue]; - -NSLog (@"%@", Nsstringfromrect (Rect2)); the - Wuyi //4. Custom Structure theStudent stu = {"Tom", -,'M'}; -Nsvalue *value5 = [Nsvalue valuewithbytes:&Stu Objctype: @encode (Student)]; WuNSLog (@"%s", @encode (Student)); - About Student stu2; $[Value5 getvalue:&STU2]; -NSLog (@"name =%s,age =%i,gender =%c", Stu2.name,stu2.age,stu2.gender); - } - return 0; A}
Common uses of the Objective-c:nsvalue class