How can I use OC to encapsulate a struct into nsvalue in iOS?
Here's how:
typedef struct{ //Custom a struct int age; int number;} Student; Nsvalue *stu=[nsvalue valuewithbytes:&stu objctype: @encode (Student)];//encapsulate the structure as an object Student value2;// Define a struct variable to accept the structure obtained from Nsvalue [Stu getvalue:&value2];//the structure in the Stu object to take out int a=value2.age; Get the fields in the structure other, the system comes with Cgpoint P=[value Cgpointvalue];
The system comes with the method of creating nsvalue and acquiring CG structure body values
Nsvalue *v=[nsvalue valuewithcgrect:cgrectmake (0, 0, 0, 0)]; CGRect rect=[v Cgrectvalue]; Nsvalue *v2=[nsvalue Valuewithcgsize:cgsizezero]; Cgsize size=[v2 Cgsizevalue]; Nsvalue *v3=[nsvalue valuewithcgpoint:cgpointmake (0, 0)]; Cgpoint P=[v3 Cgpointvalue];
Original address:http://blog.csdn.net/yangbingbinga/article/details/43114469
iOS Development Package Custom structure object, Cgrect,cgsize common structure basic use