nsmutablearray

Differences between [NSArray arrayWithArray:] and [NSArray copy]

匆匆过客 提交于 2019-12-03 09:50:31
lately I work much with arrays and I'm wonder.. what's diffrences between those two lines. NSArray *array = [NSArray arrayWithArray:someArray]; and NSArray *array = [someArray copy]; Which of it is faster? What in case we have NSMutableArray and mutableCopy ? Which of it is faster? Don't worry about it. Premature optimization. The main difference: the first approach results in an autoreleased "copy" that you don't own and don't have to release, while you do own the object created on the second line. Both arrays will be immutable, by the way. In addition to the other answers, also note, that

NSMutableArray - Remove duplicates

妖精的绣舞 提交于 2019-12-03 09:19:25
问题 i tried doing this: Values = [[NSSet setWithArray:Values] allObjects]; and no sucess, Thanks 回答1: 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. 回答2: 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 = [

Performance issues with NSMutableArray and NSArray

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've been programming C/C++ for 20 years but I'm new to objective-c and Coco and have some questions about the performance of NSMutableArray and NSArray. I need an container much like the stl list container, but coco doesn't seem to have one and inserting and removing elements from the middle of MSMutableArray seems slow, but treating it like a stl vector isn't that fast either. Also, MSMutableArray seems to only store Objects, so keep tracking of a simple data type line int or float incurs additional overhead of creating Objects

Inheritance Issues in Objective C

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I created an "SDMutableGrid" class so that I could use a grid. It's just a child of NSMutableArray that contains a number for arrays equal to the number of rows in the grid. Currently, the program quits before it really starts and it appears that it is because the methods defined for NSMutableArray somehow do not apply to SDMutableGrid, anyone know why? Here is the .h : #import <Foundation/Foundation.h> #import "SDDimensions.h" @interface SDMutableGrid : NSMutableArray { SDDimensions dimensions; } @property (nonatomic) SDDimensions

crashes my app [NSMutableArray1 removeAllObjects] iphone sdk

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i use this code to check if any objects exist in my NSMutableArray if yes i remove them all but it crashes although there are objects why? if([NSMutableArray1 count]==1) { [poemoptionslist removeAllObjects]; } if ([NSMutableArray1 count]==0) { [poemoptionslist addObject: final1]; } CONSOLE OUTPUT 2010-10-18 03:42:13.166 app1[33398:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object' * Call stack at first throw: ( 0

iPhone SDK Xcode - How to get all the filenames in the documents dir

此生再无相见时 提交于 2019-12-03 08:24:24
I want to get all the filenames in my application's documents folder, and place them in an NSMutableArray . Nothing more, nothing less. There is a convenient method in NSFileManager : NSFileManager *fileManager = [[NSFileManager alloc] init]; NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil]; ... [fileManager release]; As of ARC you can of course drop the release statement. 来源: https://stackoverflow.com/questions/7064190/iphone-sdk-xcode-how-to-get-all-the-filenames-in-the-documents-dir

How do I alphabetically sort a custom object field within a NSMutable Array?

别来无恙 提交于 2019-12-03 08:14:46
I have a custom object like: #import <Foundation/Foundation.h> @interface Store : NSObject{ NSString *name; NSString *address; } @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSString *address; @end I have an array of NSMutableArray (storeArray) containing Store objects: store1 = [[Store alloc] init]; store1.name = @"Walmart"; store1.address = @"walmart address here.."; store2 = [[Store alloc] init]; store2.name = @"Target"; store2.address = @"Target address here.."; store3 = [[Store alloc] init]; store3.name = @"Apple Store"; store3.address = @"Apple store

What's the best way to store and retrieve multi-dimensional NSMutableArrays?

﹥>﹥吖頭↗ 提交于 2019-12-03 08:06:59
I'm storing a bunch of data in a .plist file (in the application documents folder), and it's structured like this: Dictionary { "description" = "String Value", "sections" = Array ( Array ( Number, ... Number ), Array ( Number, ... Number ) ), "items" = Array ( Array ( Number, ... Number ), Array ( Number, ... Number ) ) } If I just retrieve it with NSMutableDictionary *d = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFile] I won't be able to replace the number objects, correct? So I'm recursing through the data right now and forming a mutable version of the whole thing, and it

Is there a literal syntax for mutable collections?

*爱你&永不变心* 提交于 2019-12-03 08:04:25
问题 I know I can create an NSArray with @[@"foo", @"bar"] or an NSDictionary with @{@0 : @"foo", @1 : @"bar"} . Is there a literal syntax for creating an NSMutableArray or an NSMutableDictionary ? 回答1: No. Just as how there isn't a syntax for creating an NSMutableString either. Mutable objects are not particularly suited to literal values. 回答2: There isn't a built in way, but I just usually use mutableCopy like this: NSMutableArray *array = [@[ @"1", @"2", @"3" ] mutableCopy]; 回答3: But, is there

NSMutableArray collection and @Synchronized blocks

假装没事ソ 提交于 2019-12-03 07:37:30
In Objective C I'm using a NSMutableArray instance from various thread and I'm using @synchronized to make it thread safe. currently all my acces to this array are protected with a @synchronized block, even objectAtIndex: method. Nevertheless I wonder which methods call really need to be protected with @synchronized. do I need to protect read access ? What would happens if 'ObjectAtIndex' is not protected and called at the same time that 'removeObject' ? If all methods are protected by a @synchronized what about performance? (I'writing a tcp/udp game server and really don't want to overprotect