nsmutablearray

NSMutableArray- removeObject results with removing object and a nil element

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Firstly, I am new with Objective C. I have my class Song that has a pair of attributes. In my main class i got a variable allSongs that is a NSMutableArray and in this array have I added all my song-objects. My problem comes when trying to call [self.allSongs removeObject:OBJECT]; Using the debugger, I can see that before the call, the list looks as expected. But after the call it will result that the targeted object will be removed but also the first element in the array will turn to nil. Is this a common pointer problem or what? Here is my

How to return an NSMutableArray from an NSSet

安稳与你 提交于 2019-12-03 02:30:59
问题 I'm able to put the contents of an NSSet into an NSMutableArray like this: NSMutableArray *array = [set allObjects]; The compiler complains though because [set allObjects] returns an NSArray not an NSMutableArray . How should this be fixed? 回答1: Since -allObjects returns an array, you can create a mutable version with: NSMutableArray *array = [NSMutableArray arrayWithArray:[set allObjects]]; Or, alternatively, if you want to handle the object ownership: NSMutableArray *array = [[set

NSMutableArray alloc init vs NSMutableArray array

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the differece between: [[NSMutableArray alloc] init] and [NSMutableArray array] 回答1: Here in [NSMutableArray array] you don't have to release array it will be released automatically. & if you will write [NSMutableArray alloc] init] you will have to release array so [[NSMutableArray array] will be equivalent to [[[NSArray alloc] init] autorelease]; 回答2: The first remains in memory until you release it, the second lasts until the end of the run loop iteration. 回答3: NSMutableArray no need to release memory and [NSMutableArray alloc]

NSMutableArray add object with order

 ̄綄美尐妖づ 提交于 2019-12-03 02:10:17
问题 I have a NSMUtableArray which has elements, for example: a,b,c,e And I want to add an object d to behind c and before e . In other words, I'd like to insert an object to a sorted array.(The object can be a custom object, too) I'd like to know : besides using for to find the position, is there any other method to implement it? It is better to use the iOS api. Thanks. 回答1: You can use -[NSArray indexOfObject:inSortedRange:options:usingComparator:] to ask an NSArray for the index where an object

How do I sort an NSMutableArray with custom objects in it?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What I want to do seems pretty simple, but I can't find any answers on the web. I have an NSMutableArray of objects, and let's say they are 'Person' objects. I want to sort the NSMutableArray by Person.birthDate which is an NSDate . I think it has something to do with this method: NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(???)]; In Java I would make my object implement Comparable, or use Collections.sort with an inline custom comparator...how on earth do you do this in Objective-C? 回答1: Compare method Either you

Rebuild an NSArray by grouping objects that have matching id numbers?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013 - 03 - 12 20 : 50 : 05.572 appName [ 4102 : 702 ] the array : ( { groupId = 1 ; name = "Dan" ; }, { groupId = 1 ; name = "Matt" ; }, { groupId = 2 ; name = "Steve" ; }, { groupId = 2 ; name = "Mike" ; }, {

Rebuild an NSArray by grouping objects that have matching id numbers?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013-03-12 20:50:05.572 appName[4102:702] the array: ( { groupId = 1; name = "Dan"; }, { groupId = 1; name = "Matt"; }, { groupId = 2; name = "Steve"; }, { groupId = 2; name = "Mike"; }, { groupId = 3; name = "John"; }, {

NSMutableArray - Add array at start

被刻印的时光 ゝ 提交于 2019-12-03 02:06:23
It is a simple pull to refresh case. I have data loaded into table and have a mutable data array at back-end, I receive a array of new data and want to add this complete array at start of existing array. One workaround is to create new array with new arrived data and then add previous array into it using addObjectsFromArray: method. Is there some workaround to add new data array to the start of previous array directly? First, build an NSIndexSet . NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0,[newArray count])]; Now, make use of NSMutableArray 's insertObjects

IOS ARC NSMutableArray do I need to removeAllObjects before alloc new memory for it

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: NSMutableArray * arrayTest ; -( void ) setContent { //must I call [array removeAllObjects]; ? arrayTest = [[ NSMutableArray alloc ] init ] [ arrayTest addObject :@ "str" ]; ... //add many objects } I call this function at different code snippet. do I need to removeAllObjects of arrayTest before , then alloc memory for arrayTest every time ? I use ARC . I don't want my app memory to increase every time I call this function. 回答1: No, what you have is fine. You don't need to call removeAllObjects under ARC or non-ARC. When the old

xcode unknown type name

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got code like this: Match.h: #import #import "player.h" @interface Match : NSObject { Player *firstPlayer; } @property (nonatomic, retain) Player *firstPlayer; @end Player.h: #import #import "game.h" @interface Player : NSObject { } - (Player *) init; //- (NSInteger)numberOfPoints; //- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSString *surname; @property (nonatomic, assign) NSInteger *player_id; @property (nonatomic, retain)