nsarray

How to add all decimal numbers in an NSMutableArray

孤者浪人 提交于 2019-12-01 12:31:05
I have a NSMutableArray which have some NSDecimalNumber in it, like (500,50.80,70,8000) Now I want to add all those decimal numbers together. I've tried to use for (NSDecimalNumber *number in self.numbersArray) { NSDecimal *sum += [number decimalValue] } But failed. Use - (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber Take a look at NSDecimalNumber Class Reference NSDecimalNumber *lNumber = [NSDecimalNumber zero]; for (NSDecimalNumber *number in self.numbersArray) { lNumber = [lNumber decimalNumberByAdding:number]; } A simple way to add all NSNumber s in an array is

Can't read from plist

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 12:08:09
问题 I'm trying to do something that I already know how to do - but it isn't working. Looking for ideas to fix this. I think it's something to do with the way Xcode 4.1 creates plist files. I'm trying to read strings from a plist file, and dump them into an NSArray. This is my code: NSString *myFile = [[NSBundle mainBundle] pathForResource:@"File1"ofType:@"plist"]; myArray = [[NSArray alloc]initWithContentsOfFile: myFile]; I created a plist file in Xcode - an array at the top level and a few

NSArray index of last object discrepancy

断了今生、忘了曾经 提交于 2019-12-01 10:56:22
Below is an example containing two arrays that return different indices for their lastObject. NSMutableArray *ary0 = [[NSMutableArray alloc] initWithArray:[NSArray arrayWithObjects:[NSDecimalNumber decimalNumberWithString:@"2"],[NSDecimalNumber one], nil]]; NSLog(@"%d",[ary0 indexOfObject:[ary0 lastObject]]); Logs 1, as expected. NSMutableArray *ary1 = [[NSMutableArray alloc] initWithArray:[NSArray arrayWithObjects:[NSDecimalNumber one],[NSDecimalNumber one], nil]]; NSLog(@"%d",[ary1 indexOfObject:[ary1 lastObject]]); Logs 0. I do not see how the index of the lastObject in ary1 is 0, even if

NSArray index of last object discrepancy

◇◆丶佛笑我妖孽 提交于 2019-12-01 08:15:55
问题 Below is an example containing two arrays that return different indices for their lastObject. NSMutableArray *ary0 = [[NSMutableArray alloc] initWithArray:[NSArray arrayWithObjects:[NSDecimalNumber decimalNumberWithString:@"2"],[NSDecimalNumber one], nil]]; NSLog(@"%d",[ary0 indexOfObject:[ary0 lastObject]]); Logs 1, as expected. NSMutableArray *ary1 = [[NSMutableArray alloc] initWithArray:[NSArray arrayWithObjects:[NSDecimalNumber one],[NSDecimalNumber one], nil]]; NSLog(@"%d",[ary1

Why does fast enumeration not skip the NSNumbers when I specify NSStrings?

我只是一个虾纸丫 提交于 2019-12-01 07:08:01
I thought that I knew how to use fast enumeration, but there is something I don't understand about it. If I create three NSString objects and three NSNumber objects and put them in an NSMutableArray : NSString *str1 = @"str1"; NSString *str2 = @"str2"; NSString *str3 = @"str3"; NSNumber *nb1 = [NSNumber numberWithInt:1]; NSNumber *nb2 = [NSNumber numberWithInt:2]; NSNumber *nb3 = [NSNumber numberWithInt:3]; NSArray *array = [[NSArray alloc] initWithObjects:str1, str2, str3, nb1, nb2, nb3, nil]; then I make do fast enumeration on all NSString objects, like this: for (NSString *str in array) {

NSArray becomes NSCFArray when passed

[亡魂溺海] 提交于 2019-12-01 06:32:08
I have a method that receives many different kinds of objects and decides what to do with them: -(void)performAction:(NSObject *)myAction withItem:(Item *)myItem { actionCount = -1; NSLog(@"-- NEW ACTION ARRAY --"); if ([myAction isMemberOfClass:[Look class]]) { currentActionArray = [self createLookArray:(Look *)myAction item:myItem]; } else if ([myAction isMemberOfClass:[Use class]]) { currentActionArray = [self createUseArray:(Use *)myAction item:myItem]; } else if ([myAction isMemberOfClass:[Exit class]]) { currentActionArray = [self createExitArray:(Exit *)myAction item:myItem]; } else if

iPhone dev - create array in init or viewDidLoad

拜拜、爱过 提交于 2019-12-01 06:15:08
In my UIViewController subclass should I initialize the NSArray of data for the UIPickerView in init or in viewDidLoad and why? Thanks. I would call it in viewDidLoad as the view can be loaded more than once (and also be unloaded, hence you might also want to reload your array). Also, it's a good idea to load data lazily on iPhone most of the time. Loading data in viewDidLoad is much lazier than init , which might end up performing better for you if you init, but don't immediately use your view controller. It depends on exactly what you intend the array to store, and how you intend to

How to add an Array of pages to a UIPageViewController in iOS 5?

狂风中的少年 提交于 2019-12-01 05:49:02
问题 Does anyone know what am I missing in order to add manually my own view controllers to the UIPageViewController methods? I currently have this and I do not know how to proceed: NSDictionary *pageViewOptions = [NSDictionary dictionaryWithObjectsAndKeys:UIPageViewControllerOptionSpineLocationKey, [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin], nil]; self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl

Storing NSArray in UIPasteboard

烈酒焚心 提交于 2019-12-01 05:47:00
I have several text files which I want to transfer between 2 Apps. (ie. free and paid versions of the same App). I'm using UIPasteboard to do this. The contents of the files are held in memory as NSArrays, and so I want to copy these NSArrays to the pasteboard (lite version), and read them from the pasteboard (full version). For some reason the data cannot be read back from the pasteboard. The data is being returned as a NSData object, rather than NSArray, which I think means that it is not in the required format for the pasteboard type I am using, which is "public.utf8-plain-text". When I

NSArray becomes NSCFArray when passed

倖福魔咒の 提交于 2019-12-01 04:32:07
问题 I have a method that receives many different kinds of objects and decides what to do with them: -(void)performAction:(NSObject *)myAction withItem:(Item *)myItem { actionCount = -1; NSLog(@"-- NEW ACTION ARRAY --"); if ([myAction isMemberOfClass:[Look class]]) { currentActionArray = [self createLookArray:(Look *)myAction item:myItem]; } else if ([myAction isMemberOfClass:[Use class]]) { currentActionArray = [self createUseArray:(Use *)myAction item:myItem]; } else if ([myAction