nsmutablearray

App Crashing: Mutating method sent to immutable object

耗尽温柔 提交于 2019-12-02 19:19:35
问题 I am trying to add an object to an NSMutableArray . Initially I assign some response data to the array, and can display it in a table view. After loading more data, it seems to be crashing when trying to add the new information to my original array. I am using AFNetworking for this: [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if(!_myArray){ _myArray = [responseObject objectForKey:@"data"]; } else{ [_myArray addObject:[responseObject

Add objects to NSMutable array with grouping

泪湿孤枕 提交于 2019-12-02 19:02:34
问题 I want my NSArray sampleData to receive actual data from parse.com database assuming like this: self.sampleData = @[ @{ @"date": @"12/5/2014", @"group": @[ @{ @"text": @"post1", @"location": @"x,y" }, @{ @"text": @"post2", @"location": @"x,y" }, @{ @"text": @"post3", @"location": @"x,y" }, @{ @"text": @"post4", @"location": @"x,y" }, @{ @"text": @"post5", @"location": @"x,y" } ] }, @{ @"date": @"12/3/2014", @"group": @[ @{ @"text": @"post6", @"location": @"x,y" }, @{ @"text": @"post7", @

NSMutableArray 删除可变数组元素

﹥>﹥吖頭↗ 提交于 2019-12-02 18:58:08
平时使用 NSMutableArray 中经常用到遍历删除数组元素的问题。 一般第一个想法是使用一下 forin 就解决了,但是老司机都会知道使用 forin 做删除操作的时候会 crash。 报错的原因是: 当数组在枚举的时候被修改了,因为数组规定在 forin 遍历的时候不能修改数组元素。 但是有一种特殊情况,就是在删除数组最后一个元素的时候可以使用 forin ,因为到最后一个元素的时候 forin 枚举已经结束了,这时候删除元素不会影响到 forin 工作。 NSMutableArray *nameArray = @[@"1", @"2", @"3", @"4"]; 使用倒序 forin 删除元素 //创建逆序遍历 NSEnumerator *enume = [nameArray reverseObjectEnumerator]; for (NSString *name in enumerator) { if ([name isEqualToString:@"2"]) { [array removeObject:name]; } } 使用 for 循环进行遍历删除 遍历整个数组,找到对应的元素,然后执行删除操作 for (int i = 0; i < count; ++i) { NSString *name = nameArray[i]; if ([name

Delete from uitableview + write to plist not working

坚强是说给别人听的谎言 提交于 2019-12-02 18:19:02
问题 i want to delete from uitableview and make it write to my plist. i'm pretty new to this objective-c iOS coding, so forgive me for mistakes Right now with my code it crashed with this : Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (11) must be equal to the number of rows contained in that section before the update (11), plus or

Difference between NSArray and NSMutableArray

旧时模样 提交于 2019-12-02 17:24:25
What is the difference b/w NSArray and NSMutableArray ? NSMutableArray (and all other classes with Mutable in the name) can be modified. So, if you create a plain NSArray , you cannot change its contents later (without recreating it). But if you create an NSMutableArray , you can change it — you'll notice it has methods like -addObject: and -insertObject:atIndex: . See the documentation for details. The "mutable" types are classes which can be changed after they've been initialized, like NSMutableString vs NSString . Jagat Dave NSArray : in NSArray we can not change index.... Means fix array.

NSMutableArray not working at all

老子叫甜甜 提交于 2019-12-02 17:16:28
问题 I'm trying to add sprites to a NSMutableArray but it's not adding them. This is what I have: NSMutableArray *tail; CCSprite *block; int j; -(void)handleTail:(CCSprite*)pos{ CGPoint point= pos.position; block = [CCSprite spriteWithFile:@"Icon-Small-50.png"]; //Adding the tail blocks block.scale = .8; block.color = ccGREEN; block.position = point; NSLog(@"Block Pos (%f,%f)",block.position.x,block.position.y); //CGPoint playerPos = piece.position; originalPos = point; if ([tail count] <

Converting NSArray to NSMutableArray [closed]

我们两清 提交于 2019-12-02 17:07:48
As above. Would be helpful to know. Thanks! Here are two options: - (NSMutableArray *)createMutableArray1:(NSArray *)array { return [NSMutableArray arrayWithArray:array]; } - (NSMutableArray *)createMutableArray2:(NSArray *)array { return [[array mutableCopy] autorelease]; } Use -mutableCopy and make sure to balance the retain count. NSMutableArray *mutableArray = [[immutableArray mutableCopy] autorelease]; dhaya Try this one NSMutableArray *array = [[NSMutableArray alloc]initWithArray:your_array_name]; 来源: https://stackoverflow.com/questions/3222122/converting-nsarray-to-nsmutablearray

Why does a (copy, nonatomic) NSMutableArray property create NSArrays?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 16:43:37
I made a mistake while creating a TableView class , and accidentally kept my @property as copy when I defined it: @property (copy, nonatomic) NSMutableArray *words; I initialised the array "correctly": (note this is the third attempt, so please ignore the fact that I'm not using mutableCopy and other better ways of doing this) NSArray *fixedWords = @[@"Eeny", @"Meeny", @"Miny", @"Moe", @"Catch", @"A", @"Tiger", @"By", @"His", @"Toe"]; NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords]; self.words = mutWords; However when I later came to reorder the array, it crashed

Objective-C Simplest way to create comma separated string from an array of objects

情到浓时终转凉″ 提交于 2019-12-02 16:28:41
So I have a nsmutablearray with a bunch of objects in it. I want to create a comma separated string of the id value of each object. rdelmar Use the NSArray instance method componentsJoinedByString: . In Objective-C: - (NSString *)componentsJoinedByString:(NSString *)separator In Swift: func componentsJoinedByString(separator: String) -> String Example: In Objective-C: NSString *joinedComponents = [array componentsJoinedByString:@","]; In Swift: let joinedComponents = array.joined(seperator: ",") If you're searching for the same solution in Swift, you can use this: var array:Array<String> = [

Attempt to insert non-property value Objective C

天涯浪子 提交于 2019-12-02 16:20:53
Hi l am trying to create a fourates lists from an restaurants Object, my application has a list of different restaurants, l want the ability for users to add favourate restaurants, and this code is not working - (IBAction)toggleFav:(id)sender { Restaurant *resto = [self restaure]; NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; [dic setObject:resto.price forKey:@"restoPrice"]; [dic setObject:resto.restaurantId forKey:@"restaurantId"]; [dic setObject:resto.restoAbout forKey:@"restoAbout"]; [dic setObject:resto.restoAddress forKey:@"restoAddress"]; [dic setObject:resto