nsmutablearray

iPhone - Crash using addObject on a NSMutableArray

匿名 (未验证) 提交于 2019-12-03 01:28:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem here. Or Maybe I'm really tired... I have a class : @interface THECLASS : UIViewController { NSMutableArray* param; } @property(nonatomic, retain) NSMutableArray* param; Inside that class I have a method that is called when the user clicks on a UISwitch inside a tableViewCell (I build the params into a IBAction method that is not shwon here) : @synthesize param; - (void) changedSelectorValue:(NSIndexPath*)indexPath isOn:(BOOL)isOn { [self.param addObject:@"eeeee"]; } This crashes the app with the following log : 2011-02-04

Collection was mutated while being enumerated error in objective C

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Below is my code. NSMutableArray *arr = [[NSMutableArray alloc] init]; [arr addObject:@"5"]; [arr addObject:@"7"]; [arr addObject:@"8"]; [arr enumerateObjectsUsingBlock:^(NSString *obj,NSUInteger idx,BOOL *stop) { [arr replaceObjectAtIndex:idx withObject:@"10"]; }]; The Exception log I got *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection was mutated while being enumerated.' *** First throw call stack: (0x1596012 0x12a3e7e 0x161ecc5 0x158fe1b 0x158fa16 0x158f925 0x2ba4 0x1e87b7 0x1e8da7 0x1e9fab

How to store CGRect values in NSMutableArray?

做~自己de王妃 提交于 2019-12-03 00:37:21
问题 How would I store CGRect objects in a NSMutableArray, and then later retrieve them? 回答1: You need to wrap the CG structures in NSValue classes. So: NSMutableArray* array = [NSMutableArray mutableArray]; [array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]]; CGRect someRect = [[array objectAtIndex:0] CGRectValue]; 回答2: CGRect rect = CGRectMake( 5, 5, 40, 30 ); NSString* rectAsString = NSStringFromCGRect( rect ); CGRect original = CGRectFromString( rectAsString ); What do you think

NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray

家住魔仙堡 提交于 2019-12-03 00:35:16
I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case. BACKGROUND: I have made a small database which is essentially an NSMutableArray containing custom objects, which we can call recordObjects. I set up the array: database = [[NSMutableArray alloc] init]; and my custom object, called "recordObject" contains the following variables and inits: NSString *name; int anInt; Bool aBool; I also synthesized methods so I can make calls like: aString = [[database objectAtIndex:someIndex] name]

Object cannot be nil error

喜欢而已 提交于 2019-12-02 23:54:48
问题 I am getting an error when I try to add a new object to dataArray . This is how I define dataArray . -(NSMutableArray *)dataArray{ if (!_dataArray){ _dataArray = [[NSMutableArray alloc] initWithObjects: [NSMutableArray arrayWithObjects: [NSMutableArray array], [NSMutableArray array], [NSMutableArray array], nil], [NSMutableArray arrayWithObjects: [NSMutableArray array], [NSMutableArray array], [NSMutableArray array], nil], nil]; } return _dataArray; } This is where I attempt to add an object

NSMutableArray - Remove duplicates

杀马特。学长 韩版系。学妹 提交于 2019-12-02 23:50:16
i tried doing this: Values = [[NSSet setWithArray:Values] allObjects]; and no sucess, Thanks kennytm Your method should work, except it returns an NSArray instead of NSMutableArray . You could use [values setArray:[[NSSet setWithArray:values] allObjects]]; to set values to the content of the new array. Sander Note that the NSSet method may remove any order you have in your NSArray . You might want to loop thru your array to keep the order. Something like this: NSMutableArray* uniqueValues = [[NSMutableArray alloc] init]; for(id e in Values) { if(![uniqueValues containsObject:e]) {

UITableView, how do I know what Section during cellForRowAtIndexPath?

陌路散爱 提交于 2019-12-02 21:34:48
I have a UITableView displaying a list of Cities. I want to separate them by State. I can't seem to figure out how to get it to pick the right items out of my Array. If Section 1 (Arizona) has 2 Cities and Section 2 (California) has 2 Cities, during cellForRowAtIndexPath, Section 2, City 1 has an index of 0, even though it's the 3rd item in my array. I thought about just turning my City Array into a State Array, where each item holds an Array of Cities, but I still don't know what section I'm on and therefore don't know which City Array under the States Array I would need to access. Yannick

Do removeAllObjects and release of an NSMutableArray both have the same functionality?

我是研究僧i 提交于 2019-12-02 21:31:59
问题 I have written the following line of code: NSMutableArray *array=[[NSMutableArray alloc]init]; This allocates some memory. My question is, how can we later release this memory, whether using removeAllObjects method or [array release]? Do both methods have the same functionality? 回答1: When you add an object to the array, the object's retain count will increase by 1. When you remove that object from the array, retain count will decrease by 1 to balance it out. But if you release the array, all

Having problems with adding objects to NSMutableArray

萝らか妹 提交于 2019-12-02 21:26:21
问题 I am having problem with adding objects to NSMutableArray *array. // Controller.m #import "Controller.h" @implementation Controller - (void)parser:(NSString *)string{ [array addObject:string]; NSLog(@"answerArray(1): %@",[array objectAtIndex:1]); [array retain]; } @end // Controller.h #import <Foundation/Foundation.h> @interface Controller : NSObject { NSMutableArray *array; } - (void)parser:(NSString *)string; @end NSLog(@"answerArray(1): %@",[array objectAtIndex:1]); Results: answerArray(1)

Cocoa structs and NSMutableArray

岁酱吖の 提交于 2019-12-02 20:34:44
I have an NSMutableArray that I'm trying to store and access some structs. How do I do this? 'addObject' gives me an error saying "Incompatible type for argument 1 of addObject". Here is an example ('in' is a NSFileHandle, 'array' is the NSMutableArray): //Write points for(int i=0; i<5; i++) { struct Point p; buff = [in readDataOfLength:1]; [buff getBytes:&(p.x) length:sizeof(p.x)]; [array addObject:p]; } //Read points for(int i=0; i<5; i++) { struct Point p = [array objectAtIndex:i]; NSLog(@"%i", p.x); } As mentioned, NSValue can wrap a plain struct using +value:withObjCType: or