nsnumber

NSNumberFormatter numberFromString returns null

若如初见. 提交于 2019-11-30 15:45:26
Here's my code NSNumberFormatter *currencyStyle = [[NSNumberFormatter alloc] init]; [currencyStyle setFormatterBehavior:NSNumberFormatterBehavior10_4]; [currencyStyle setNumberStyle:NSNumberFormatterCurrencyStyle]; NSNumber *amount = [[NSNumber alloc] init]; NSLog(@"the price string is %@", price); amount = [currencyStyle numberFromString:price]; NSLog(@"The converted number is %@",[currencyStyle numberFromString:price]); NSLog(@"The NSNumber is %@", amount); NSLog(@"The formatted version is %@", [currencyStyle stringFromNumber:amount]); NSLog(@"--------------------"); self.priceLabel.text =

NSNumber >= 13 won't retain. Everything else will

半城伤御伤魂 提交于 2019-11-30 15:32:09
The code I'm currently working on requires adding an NSNumber object to an array. All of the NSNumbers with value 0-12 are added fine, but 13 onward causes a EXC_BAD_ACCESS. I turned on NSZombieEnabled and am now getting *** -[CFNumber retain]: message sent to deallocated instance 0x3c78420 . Here's the call stack: #0 0x01eac3a7 in ___forwarding___ #1 0x01e886c2 in __forwarding_prep_0___ #2 0x01e3f988 in CFRetain #3 0x01e4b586 in _CFArrayReplaceValues #4 0x0002a2f9 in -[NSCFArray insertObject:atIndex:] #5 0x0002a274 in -[NSCFArray addObject:] #6 0x00010a3b in -[Faves addObject:] at Faves.m:24

Compare a NSNumber to an int

和自甴很熟 提交于 2019-11-30 11:12:57
I've a simple question (I think): I'm trying to compare a NSNumber with a int, to see if it is 0 or 1. Here is the code: id i = [dictionary objectForKey:@"error"]; //class = NSCFNumber NSLog(@"%@ == 0 -> %@", i, i == 0); NSLog(@"%@ == 0 -> %@", i, [i compare:[NSNumber numberWithBool:NO]]); I tried this to methods but I get null as result: 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) Can you help me? The result of comparison is a BOOL which is not an Objective-C object. Therefore you should not print it using %@ . Try %d instead

how to convert NSNumber to int in Objective-C

为君一笑 提交于 2019-11-30 10:19:51
问题 Before putting int value into dictionary i have set the int value as [NSNumber numberWithInt:2], now when i try to retrieve back the dictionary content , i want it back in int format.. hw to do this?? here's my code; NSMutabelDictionary *dict = [[NSMutableDictionary alloc]init]; int intValue = 300; [dict setObject:[NSNumber numberWithInt:intValue] forKey:@"integer"]; retriving......... int number = [dict ObjectForKey:@"integer"]; .. it throws an exception sayin casting is required.. when i do

NSNumber vs Int

瘦欲@ 提交于 2019-11-30 08:58:16
问题 If integers cannot be written to a dictionary and then to a .plist, but NSNumbers can is it better to use NSNumbers throughout the app, rather than needing to convert every-time saving or loading a dictionary from a .plist? 回答1: As a generalization: Just stick with POD types until you need to use an object based representation, such as NSNumber . The performance is much better with the PODs, but you'll need NSNumber in some cases. In some cases, it may make sense to use NSNumber instead --

NSNumberFormatter numberFromString returns null

若如初见. 提交于 2019-11-29 22:56:40
问题 Here's my code NSNumberFormatter *currencyStyle = [[NSNumberFormatter alloc] init]; [currencyStyle setFormatterBehavior:NSNumberFormatterBehavior10_4]; [currencyStyle setNumberStyle:NSNumberFormatterCurrencyStyle]; NSNumber *amount = [[NSNumber alloc] init]; NSLog(@"the price string is %@", price); amount = [currencyStyle numberFromString:price]; NSLog(@"The converted number is %@",[currencyStyle numberFromString:price]); NSLog(@"The NSNumber is %@", amount); NSLog(@"The formatted version is

Compare a NSNumber to an int

自古美人都是妖i 提交于 2019-11-29 16:49:33
问题 I've a simple question (I think): I'm trying to compare a NSNumber with a int, to see if it is 0 or 1. Here is the code: id i = [dictionary objectForKey:@"error"]; //class = NSCFNumber NSLog(@"%@ == 0 -> %@", i, i == 0); NSLog(@"%@ == 0 -> %@", i, [i compare:[NSNumber numberWithBool:NO]]); I tried this to methods but I get null as result: 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) Can you help me? 回答1: The result of

NSNumber vs Int

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 10:00:52
If integers cannot be written to a dictionary and then to a .plist, but NSNumbers can is it better to use NSNumbers throughout the app, rather than needing to convert every-time saving or loading a dictionary from a .plist? As a generalization: Just stick with POD types until you need to use an object based representation, such as NSNumber . The performance is much better with the PODs, but you'll need NSNumber in some cases. In some cases, it may make sense to use NSNumber instead -- this is typically when you reuse a NSNumber often -- this is to avoid making a ton of duplicate NSNumber s.

NSNumber Literals

橙三吉。 提交于 2019-11-29 07:48:34
I am very new to Objective-C. I know C and C++ but Objective-C has quite the learning curve. Anyway, is there a shorter way (possibly by some kind of NSNumber literal if such exists) to write the following: [Tyler setArms:[[[NSNumber alloc] autorelease] initWithInt:1]]; Yes, just use one of the many helper functions such as numberWithInt: : [Tyler setArms:[NSNumber numberWithInt:1]]; The expression [NSNumber numberWithInt:1] is equivalent to [[[NSNumber alloc] initWithInt:1] autorelease] , which is equivalent to [[[NSNumber alloc] autorelease] initWithInt:1] . The latter expression is

How to read crash log? How to find why the app crashes in system library? What means EXC_CRASH (SIGABRT)?

烈酒焚心 提交于 2019-11-29 07:10:59
I got an crash logs from a customer to figure why my app crash on her iPhone. Here some info from crash log: Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x00000000, 0x00000000 Crashed Thread: 0 Stack trace for Thread 0 Thread 0 Crashed: 0 libSystem.B.dylib 0x3293f98c 0x328c1000 + 518540 1 libSystem.B.dylib 0x3293f97c 0x328c1000 + 518524 2 libSystem.B.dylib 0x3293f96e 0x328c1000 + 518510 3 libSystem.B.dylib 0x3295461a 0x328c1000 + 603674 4 libstdc++.6.dylib 0x30a143b0 0x309cf000 + 283568 5 libobjc.A.dylib 0x3347a858 0x33475000 + 22616 6 libstdc++.6.dylib 0x30a12776 0x309cf000 + 276342