nsnumber

Objective-C understanding isKindOfClass

被刻印的时光 ゝ 提交于 2020-01-05 02:50:22
问题 Latest version of Objective-C and XCode (4.4). I have a code snippet and I cannot understand why I'm able to use some lines, let me explain : // For understanding purpose : (NSMutableArray*)_programStack id l_topItemOnStack = [_programStack lastObject]; if([l_topItemOnStack isKindOfClass:[NSNumber class]]) { return [l_topItemOnStack doubleValue]; } My question : since my l_topItemOnStack is of type id and I didn't cast it into a NSNumber , how am i able to use the [l_topItemOnStack

iOS 8 number conversion/formatting error? (cannot reproduce)

余生长醉 提交于 2020-01-02 05:02:07
问题 The following method takes input from a UITextField and formats it for display. This code has worked flawlessly for years, but a problem was just reported on the iPhone 6 Plus using iOS 8.1. It happens every time for the user but I have not been able to reproduce it. I believe it has to do with NSNumber/NSDecimalNumber conversions and formatting on iOS 8, perhaps for a 64-bit app/device. The keyboard used for input is a number pad, so the only text that can be entered into the textfield are

Objective-C: Find numbers in string

梦想的初衷 提交于 2019-12-27 12:18:50
问题 I have a string that contains words as well as a number. How can I extract that number from the string? NSString *str = @"This is my string. #1234"; I would like to be able to strip out 1234 as an int. The string will have different numbers and words each time I search it. Ideas? 回答1: Here's an NSScanner based solution: // Input NSString *originalString = @"This is my string. #1234"; // Intermediate NSString *numberString; NSScanner *scanner = [NSScanner scannerWithString:originalString];

Objective-C: Find numbers in string

旧时模样 提交于 2019-12-27 12:18:04
问题 I have a string that contains words as well as a number. How can I extract that number from the string? NSString *str = @"This is my string. #1234"; I would like to be able to strip out 1234 as an int. The string will have different numbers and words each time I search it. Ideas? 回答1: Here's an NSScanner based solution: // Input NSString *originalString = @"This is my string. #1234"; // Intermediate NSString *numberString; NSScanner *scanner = [NSScanner scannerWithString:originalString];

NSNumber comparision iOS SDK 4.2 vs 5, in Objective-C?

女生的网名这么多〃 提交于 2019-12-25 04:06:55
问题 I found a bug in my app: The logic was that I was comparing two NSNumbers using "==", and I believe it used to work. But it no longer passes on iOS sdk 5, so I need to use isEqualToNumber instead. Can anyone with iOS sdk 4.2 please try and run the following code and give me the result. I tried to revert to older Xcode to test it myself, but I was not able to do that. NSNumber *num1 = [NSNumber numberWithInt:100]; NSNumber *num2 = [NSNumber numberWithInt:100]; if (num1 == num2) { NSLog(@"==

Incremenent NSnumber every 5 seconds - Cocos2d

寵の児 提交于 2019-12-24 05:55:04
问题 I am trying to increment a NSNumber every 5 seconds by 1 in Cocos2d but for some reason it isn't working (probably obvious mistake). I am using the update method but I think this may be the wrong place. Currently it is only adding +1 once. I need it to do this every 5 seconds constantly: -(void) update: (CCTime) delta { // Save a string: NSNumber *anInt = [NSNumber numberWithInt:500]; NSNumber *bNumber = [NSNumber numberWithInt:[anInt intValue] + 1]; NSLog(@"Update Number%@",bNumber); } 回答1:

How can i get the locale from currency names list

限于喜欢 提交于 2019-12-24 04:31:41
问题 i am making a currency selecting screen.for that i am displaying the list of currencies using the following code to create an array of currencies from which a tableview is populated NSArray *countryArray = [NSLocale ISOCurrencyCodes]; for(NSString *country in countryArray) { //NSLog(@"%@",[[NSLocale currentLocale] displayNameForKey:NSLocaleCurrencyCode value:country]); if([[NSLocale currentLocale] displayNameForKey:NSLocaleCurrencyCode value:country]) { [countriesArray addObject:[[NSLocale

What's the largest value an NSNumber can store?

社会主义新天地 提交于 2019-12-23 07:56:12
问题 What's the largest value an NSNumber can store? // ok NSNumber *value = @(1 << 31); // gives compiler error, so max NSNumber is 32-bit uint? NSNumber *value = @(1 << 32); 回答1: NSNumber is actually a class cluster, meaning that when you create an instance you may be getting any of a variety of concrete subclasses, each capable of storing a different kind of numeric type. The actual types available, and their sizes, may be machine-dependent. Looking at the NSNumber documentation shows you the

Unable to change NSNumber to Double and do some calculations with it

女生的网名这么多〃 提交于 2019-12-23 05:55:09
问题 my problem is that i have an Array that holds some double values NSArray *level4results = [context executeFetchRequest:request error:&error]; then i sum up all the values in that array NSNumber *l4sum = [level4results valueForKeyPath:@"sum.self"]; The next thing i want to do is to divide by 8 the sum of the array... and this is where i am stuck. I have tried many options and ways of doing it by either way i kept on getting different error. This is what i have currently in my code double

Why is NSNumber immutable?

半腔热情 提交于 2019-12-22 01:33:29
问题 Why is NSNumber immutable? Was there a good reason? Because now I am thinking about creating my own class just for the sake of mutability. 回答1: A number is a very basic data type. A number is just that - a number. If you mutate it, it just happens to be something else. A number simply cannot change. Compare that with more complex data, where the object itself still represents the same thing. 回答2: Immutable numbers save space. Assume that your program creates many NSNumber s, and most of them