OBJECTIVE-C Foundation compaction article--nsvalue&nsnumber (packing and unpacking)

Source: Internet
Author: User

Overview

NSNumber and Nsvalue are used for boxing purposes, and the basic types of data are loaded into objects. The information given in the official documentation is clearly stated:

/*nsvalue.hcopyright (c) 1994-2014, Apple Inc. All rights reserved.*/#import <Foundation/NSObject.h> @class nsstring, nsdictionary; @interface nsvalue:nsobject <nscopying, nssecurecoding>-(void) GetValue: (void *) value; @property (readonly) const char *objctype ns_returns_ inner_pointer;-(Instancetype) initwithbytes: (const void *) value objctype: (const char *) Type Ns_designated_initializer ;-(Instancetype) Initwithcoder: (Nscoder *) Adecoder ns_designated_initializer; @end @interface NSValue ( nsvaluecreation) + (Nsvalue *) Valuewithbytes: (const void *) value objctype: (const char *) type;+ (Nsvalue *) Value: (const void *) value withobjctype: (const char *) type; @end @interface nsvalue (nsvalueextensionmethods) + (Nsvalue *) Valuewithnonretainedobject: (ID) anobject; @property (nonatomic, readonly) ID nonretainedobjectvalue;+ (Nsvalue *) Valuewithpointer: (const void *) pointer;-(void *) pointervalue;-(BOOL) Isequaltovalue: (Nsvalue *) value; @end @interface nsnumber:nsvalue-(instancetype) Initwithcoder:(Nscoder *) Adecoder ns_designated_initializer;-(NSNumber *) Initwithchar: (char) value ns_designated_initializer;-( NSNumber *) Initwithunsignedchar: (unsigned char) value ns_designated_initializer;-(NSNumber *) Initwithshort: (short) Value ns_designated_initializer;-(NSNumber *) Initwithunsignedshort: (unsigned short) value Ns_designated_initializer ;-(NSNumber *) Initwithint: (int) value ns_designated_initializer;-(NSNumber *) Initwithunsignedint: (unsigned int) Value ns_designated_initializer;-(NSNumber *) Initwithlong: (long) value ns_designated_initializer;-(NSNumber *) Initwithunsignedlong: (unsigned long) value ns_designated_initializer;-(NSNumber *) Initwithlonglong: (Long Long) value ns_designated_initializer;-(NSNumber *) Initwithunsignedlonglong: (unsigned long) value ns_designated_ initializer;-(NSNumber *) Initwithfloat: (float) value ns_designated_initializer;-(NSNumber *) Initwithdouble: (Double ) Value ns_designated_initializer;-(NSNumber *) Initwithbool: (BOOL) value Ns_designated_initializer;-(NSNumber *) Initwithinteger: (Nsinteger) value ns_available (10_5, 2_0) ns_designated_initializer;-(NSNumber *) Initwithunsignedinteger: (Nsuinteger) value ns_available (10_5, 2_0) Ns_designated_initializer; @property (readonly) char charvalue; @property (readonly) unsigned char unsignedcharvalue; @property (readonly) short shortvalue; @property ( readonly) unsigned short unsignedshortvalue; @property (readonly) int intvalue; @property (readonly) unsigned int Unsignedintvalue; @property (readonly) long Longvalue; @property (readonly) unsigned long unsignedlongvalue; @property ( ReadOnly) long long Longlongvalue; @property (readonly) unsigned long long unsignedlonglongvalue; @property (readonly) float Floatvalue; @property (readonly) double doublevalue; @property (readonly) BOOL boolvalue; @property (readonly) Nsinteger IntegerValue ns_available (10_5, 2_0); @property (readonly) Nsuinteger unsignedintegervalue ns_available (10_5 , 2_0); @property (readonly, copy) NSString *stringvalue;-(nscomparisonresult) comPare: (NSNumber *) othernumber;-(BOOL) Isequaltonumber: (NSNumber *) number;-(NSString *) Descriptionwithlocale: (ID) Locale, @end @interface nsnumber (nsnumbercreation) + (NSNumber *) Numberwithchar: (char) value;+ (NSNumber *) Numberwithunsignedchar: (unsigned char) value;+ (NSNumber *) Numberwithshort: (short) value;+ (NSNumber *) Numberwithunsignedshort: (unsigned short) value;+ (NSNumber *) Numberwithint: (int) value;+ (NSNumber *) Numberwithunsignedint: (unsigned int) value;+ (NSNumber *) Numberwithlong: (Long) value;+ (NSNumber *) Numberwithunsignedlong: (unsigned long) value;+ (NSNumber *) Numberwithlonglong: (Long Long) value;+ (NSNumber *) Numberwithunsignedlonglong: (unsigned long Long) value;+ (NSNumber *) Numberwithfloat: (float) value;+ (NSNumber *) Numberwithdouble: (Double) value;+ (NSNumber *) Numberwithbool: (BOOL) value;+ (NSNumber *) Numberwithinteger: (NSInteger ) value ns_available (10_5, 2_0); + (NSNumber *) Numberwithunsignedinteger: (Nsuinteger) value ns_available (10_5, 2_0); @ End

The main contents of this article are as follows:

  1. Document Description

2. test Procedures

Document description

NSNumber is inherited from the nsvalue. Nsvalue can be any value, NSNumber is mainly used to deal with the basic data types we commonly use. the use of nsvalue also needs to be learned in depth.

NSNumber has a fast syntax: You can encapsulate objects with @ such as @yes. Specific in the test procedures are described.

Test program
  main.m//  nsnumber&nsvalue////  Created by HUSHUNFENGMAC-CMCC on 15/7/8.//  Copyright (c) 2015 HUSHUNFENGMAC-CMCC. All rights reserved.//#import <foundation/foundation.h>int Main (int argc, const char * argv[]) {    @ Autoreleasepool {        //Insert code        here ... NSNumber *intnum = [NSNumber numberwithint:10];        int i = Intnum.intvalue;        NSLog (@ "%d", I);                        Fast syntax        nsnumber *boolnum = @YES;        BOOL x = boolnum.boolvalue;        BOOL y = [boolnum boolvalue];                NSLog (@ "%i", x);        NSLog (@ "%i", y);                NSLog (@ "Hello, world!");    }    return 0;}

OBJECTIVE-C Foundation compaction article--nsvalue&nsnumber (packing and unpacking)

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.