Converting iOS NSNumber to NSString description, nsnumbernsstring

Source: Internet
Author: User

Converting iOS NSNumber to NSString description, nsnumbernsstring

We often need to convert a number into a string. You can use description when you do not need to match other strings.

1/** 2 description Is NSObject. When the value 3 is NSNumber, stringWithFormate is not used to convert it into a string. ease of use 4 is useful when parsing/assigning values. When we need NSString, the data given to us is NSNumber .. 5 */6 7 // The NSNumber 8 NSDictionary * dict =@{ 9 @ "1": @ "2": @ "3 ": @ 3}; 12 // The retrieved NSNumber is converted to NSString13 NSString * str = [dict [@ "2"] description]; 14 NSLog (@ "str = % @", str); 15 16 // The data retrieved from the dictionary is NSString17 NSDictionary * dict2 =@{@ "1": @ "1", 18 @ "2": @ "2 ", 19 @ "3": @ "3"}; 20 // because it is a string, here, the description method does not actually work. 21 NSString * str2 = [dict2 [@ "2"] description]; 22 NSLog (@ "str2 = % @", str2 );

 

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.