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 );