NSNumber (encapsulate basic data types)

Source: Internet
Author: User

NSNumber (encapsulate basic data types)

//// Main. m // OC05-task-04 // Created by Xin the Great on 15-1-26. // Copyright (c) 2015 Xin the Great. all rights reserved. // # import
 
  
Int main (int argc, const char * argv []) {@ autoreleasepool {// insert code here... //// // NSNumber ///////////////// ////// encapsulate the basic data type int intValue = 100; float floatValue = 3.14; BOOL boolValue = YES; NSNumber * intNumber = [[NSNumber alloc] initWithInt: intValue]; NSLog (@ "intNumber is % @", intNumber ); NSNumber * floatNumber = [NSNumber numberWithFloat: floatValue]; NSLog (@ "floatNumber is % @", floatNumber); NSNumber * boolNumber = [NSNumber numberWithBool: boolValue]; NSLog (@ "boolNumber is % @", boolNumber); // you can put it in the container after packaging NSArray * arr = @ [intNumber, floatNumber, boolNumber]; NSLog (@ "arr is % @", arr); // restore to the basic data type float value = [floatNumber floatValue]; int value2 = [intNumber intValue]; NSLog (@ "value is %. 2f ", value); NSLog (@" value2 is % d ", value2); // method NSNumber * intNum = @ 80; // ----> NSNumber * intNumber = [[NSNumber alloc] initWithInt: 80]; NSNumber * floatNum = @ 3.14; // ----> [NSNumber numberWithFloat: 3.14]; NSNumber * boolNum = @ YES; // ---> [NSNumber numberWithBool: YES]; NSNumber * charNum = @ 'a'; // ---> [NSNumber numberWithChar: 'a']; // calculate NSNumber * number = @ (1 + 2); // write NSArray * arr1 = @ [@ "string", @ 12, intNum, floatNum, boolNum, charNum, number]; NSLog (@ "arr1 is % @", arr1);} return 0 ;}
 

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.