Simple knowledge about NSNumber & Nsvalue's methodology

Source: Internet
Author: User

Simple sharing under, hope that Daniel more guidance maze, gradually revise, perfect insufficient support. For reference, please also understand

#import <Foundation/Foundation.h>

typedef struct{//c-Structural Body

int year;

int month;

int day;

}date;

void text () {

Date mydate; To define a struct-body variable

Date date={2016,8,20};

Char *[email protected] (Date); Generate a corresponding type description string based on struct type

void* represents any pointer. This is going to be the address of the struct &date

Nsvalue *val=[nsvalue value:&date Withobjctype:type];

[Val Objctype]; Remove type description string

[Val getvalue:&mydate]; Remove the packaged structure

NSLog (@ "%i-%i-%i", mydate.year,mydate.month,mydate.day); . Represents an Access member

}

int main (int argc, const char * argv[]) {

@autoreleasepool {

#pragma mark NSNumber common methods

Can only be packed with numbers, cannot package structures, and does not support automatic unpacking of packages

NSNumber *num=[nsnumber Numberwithint:10];

wrapping int Type 10 to a NSNumber object

Nsmutablearray *array=[nsmutablearray Array];

[Array addobject:num]; Adding values to the array

NSNumber *num1=[array Lastobject];

Removed is still a NSNumber object, does not support automatic unpacking

int NUMBER=[NUM1 Intvalue]; Convert NSNumber to int type

[Email protected]; quickly wrap digital objects

#pragma mark Nsvalue Common methods

Wrapper class, Nsvalue is the parent class of nsnumber, can wrap any value

Cgpoint Point=cgpointmake (10, 10);

Nsvalue *value=[nsvalue Valuewithpoint:point];

Wrapping a struct as an object

[Array Addobject:value]; Add Value

Nsvalue *v1=[array Lastobject];

Cgpoint P1=[v1 Pointvalue]; Remove the value put in

BOOL Re=cgpointequaltopoint (Point, p1); Comparison of Judgments

Nsvalue *[email protected] ' a '; Fast wrapper character, print out ANSCII code: 97

Text ();

}

return 0;

}

Simple knowledge about NSNumber & Nsvalue's methodology

Related Article

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.