nsmutablearray

How to add alive object to NSMutableArray and remove them when they're released?

匆匆过客 提交于 2019-12-18 06:54:21
问题 I have class Item and class List (which has an NSMutableArray). Every time class Item is instantiated (and destroyed) it posts a notification, which is listened-to by class List. When class List receives the notification is adds the instance of class Item to its list. I'm trying to have class Item also post a notification that its about to be dealloc'd. The problem is that class List's NSMutableArray retains the instance of class Item. What's the most appropriate means of handling this

How to add alive object to NSMutableArray and remove them when they're released?

落花浮王杯 提交于 2019-12-18 06:52:09
问题 I have class Item and class List (which has an NSMutableArray). Every time class Item is instantiated (and destroyed) it posts a notification, which is listened-to by class List. When class List receives the notification is adds the instance of class Item to its list. I'm trying to have class Item also post a notification that its about to be dealloc'd. The problem is that class List's NSMutableArray retains the instance of class Item. What's the most appropriate means of handling this

Avoid copying NSMutableArray for reading with multithreaded writes

家住魔仙堡 提交于 2019-12-18 06:22:27
问题 I have a class that uses a mutable array that is modified once after a lot of reads (new items arrive). The problem is that when times comes to mutate the array, reads keep coming. Currently to avoid this issue every time it reads something it does so over a copy: [[theArray copy] operation] //operation being indexOfObject:, objectAtIndex: objectsAtIndexes:, etc. The copy is becoming really expensive, especially when there is no need to (all those times when the array is not being mutated).

Static NSArray of strings - how/where to initialize in a View Controller

那年仲夏 提交于 2019-12-17 23:20:57
问题 In a Master-Detail app I'd like to display a TableView with 5 sections titled: Your Move Their Move Won Games Lost Games Options So I create a blank Master-Detail app in Xcode 5.0.2 and then in its MasterViewController.m (which is a UITableViewController) I'm trying to implement the method: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return _titles[section]; } My question is however how to init the NSArray _titles? I'm trying in the

how to add nil to nsmutablearray?

元气小坏坏 提交于 2019-12-17 22:34:53
问题 NSArray *array = [[NSArray alloc] initWithObjects:@"ΕΛΤΑ", @"ΕΛΤΑ COURIER", @"ACS", @"ACS ΕΞΩΤΕΡΙΚΟ", @"DHL", @"INTERATTICA", @"SPEEDEX", @"UPS", @"ΓΕΝΙΚΗ ΤΑΧΥΔΡΟΜΙΚΗ", @"ΜΕΤΑΦΟΡΙΚΕΣ ΕΞΩΤΕΡΙΚΟΥ", nil]; This is working because it has nil at the end. But I add objects like this: addObject:name etc... So at the end I have to add nil I do this addObhect:nil but when I run the app it still crashes at cellForRowAtIndexPath: how can I do this work? Ok, I dont have to add nil What is the reason that

What is the data structure behind NSMutableArray?

本小妞迷上赌 提交于 2019-12-17 22:34:22
问题 Usually, a "mutable array" class is implemented as a wrapper around a simple array. The wrapper allocates more memory when you add an element past the end. This is a common data structure and the performance of the various operations is well known. You get O(1) element access, O(N) insert and remove, or O(1) (on average) insert and remove at the end of the array. But NSMutableArray is something else. For example the docs say [emphasis mine]: Note: Most operations on an array take constant

NSCFString countByEnumeratingWithState:objects:count: ERROR while searching NSMutableArray

时间秒杀一切 提交于 2019-12-17 19:55:00
问题 I have the following situation where I have an NSMutableArray filled with an xml file which I want to search. When I enter something in the search field I get this Error: -[NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x5b388b0 What does it means and how can I fix it?? I suppose the error is somewhere around here. - (void)searchTableView{ searchedList = [[NSMutableArray alloc] init]; NSLog(@"new list %@", searchedList); NSString *searchText =

Objective C: how to check if variable is NSArray or NSMutableArray

无人久伴 提交于 2019-12-17 18:18:14
问题 How can i check if a variable is an NSArray or an NSMutableArray? 回答1: *Note that the implementation of NS{,Mutable}Array has changed since this answer was written. As a result, isKindOfClass: now works. On what platforms where and when, I don't know. Until it is documented as safe to do so, I would strongly recommend NOT writing code that tries to detect whether a collection is mutable or immutable. Even if it were safe, such a design pattern is almost always indicative of a serious design

Disadvantage of using NSMutableArray vs NSArray?

最后都变了- 提交于 2019-12-17 17:54:27
问题 I'm using an array to store cached objects loaded from a database in my iPhone app, and was wondering: are there any significant disadvantages to using NSMutableArray that I should know of? edit: I know that NSMutableArray can be modified, but I'm looking for specific reasons (performance, etc..) why one would use NSArray instead. I assume there would be a performance difference, but I have no idea whether it's significant or not. 回答1: If you're loading objects from a database and you know

Collection was mutated while being enumerated error in objective C

[亡魂溺海] 提交于 2019-12-17 16:38:05
问题 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 <__NSArrayM: 0x742a580> was mutated while being enumerated.' *** First throw call stack: (0x1596012 0x12a3e7e