nsmutablearray

How to return an NSMutableArray from an NSSet

北慕城南 提交于 2019-12-02 16:02:22
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? 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 allObjects] mutableCopy]; I resolved crashing by using NSMutableArray's method 'addObjectsFromArray' to assign all

NSMutableArray add object with order

二次信任 提交于 2019-12-02 15:43:50
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. You can use -[NSArray indexOfObject:inSortedRange:options:usingComparator:] to ask an NSArray for the index where an object should be inserted given an array range that’s currently sorted. For example, assuming the entire array is

Access NSMutableArray from a different class

删除回忆录丶 提交于 2019-12-02 15:21:41
问题 I have a class where a NSMutableArray object is formed, as so: navBarColour = [[NSMutableArray alloc] initWithObjects:colourOfNavBar, nil]; I then have another class, which has the first class added to it properly, but it won't let me access the NSMutableArray from the first class. This line of code: NSLog(@"%@", [HandlingPalettes.navBarColour objectAtIndex:0]); Returns: expected ':' before '.' token But: NSLog(@"%@", [navBarColour objectAtIndex:0]); would work in the original class. What am

Storing NSMutableArray filled with custom objects in NSUserDefaults - crash

六月ゝ 毕业季﹏ 提交于 2019-12-02 13:38:36
EDIT: Here is a working version. I was able to retrieve my object within the NSMUtableArray after I saved and loaded it from the NSUserDefaults via NSCoding. I think it's important to mention, that you not only need to de-archive the array, but also all its content. As you can see, I had to not only store the NSData of my freeze object, but also the NSData of my array: // My class "Freeze" @interface Freeze : NSObject <NSCoding> // The NSCoding-protocoll is important!! { NSMutableString *name; } @property(nonatomic, copy) NSMutableString *name; -(void) InitString; @end @implementation Freeze

access to array object

北慕城南 提交于 2019-12-02 13:31:44
i create an array and i initialize it with objects. i tried to get access to the array object but i get a (null). what do i do wrong? photoArray = [[NSMutableArray alloc] init]; PhotoItem *photo1 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"1.jpg"] name:@"roy rest" photographer:@"roy"]; PhotoItem *photo2 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"2.jpg"] name:@"roy's hand" photographer:@"roy"]; PhotoItem *photo3 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"3.jpg"] name:@"sapir first" photographer:@"sapir"]; PhotoItem *photo4 = [[PhotoItem alloc]

how to remove duplicate value in NSMutableArray

拜拜、爱过 提交于 2019-12-02 13:10:25
问题 i'm scanning wifi info using NSMutableArray, but there are few duplicate values appear, so i try to use following code but still getting the duplicate values, if([scan_networks count] > 0) { NSArray *uniqueNetwork = [[NSMutableArray alloc] initWithArray:[[NSSet setWithArray:scan_networks] allObjects]]; [scan_networks removeAllObjects]; NSSortDescriptor *networkName = [[[NSSortDescriptor alloc] initWithKey:@"SSID_STR" ascending:YES] autorelease]; NSArray *descriptors = [NSArray

Getting Top 10 Highest Numbers From Array?

≯℡__Kan透↙ 提交于 2019-12-02 11:58:43
问题 I am having a bit of a issue. I have an NSMutableDictionary with 10 NSMutableArrays in it. Each array has somewhere between 0-10 numbers which could each be any integer, e.g. 12 or 103. What I need to do is get the top 10 highest numbers from across each of the arrays. The trouble is, I need to keep a reference of the array it came from in the dictionary (the key) and the index position of the number from the array it came form. 回答1: Easiest way, is to sort the array in Descending order, and

Having problems with adding objects to NSMutableArray

﹥>﹥吖頭↗ 提交于 2019-12-02 11:43:18
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): (null) First off, you're over-retaining the array. Second, you didn't provide the code for

How to access/print an NSMutableArray element from one view to another view?

大憨熊 提交于 2019-12-02 11:01:11
问题 I have an NSMutableArray named mArray in view1 and it stores some strings. Now I want to access/print/compare these elements in view2 . Please guide me. 回答1: write property synthesize for marray in view1 class.Then create view1 object in the view2 and use as view1object.marray 回答2: Suggestion: You could put the array in your Controller class,where they both could access. It is always better to have sharable data in Controller then views if data has to be shared among views. 回答3: view1.mArray

CGMutablePathRef to NSMutableArray

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 10:51:49
How to add CGMutablePathRef to NSMutableArray? CGMutablePath path = <... your path ...>; [mutableArray addObject:(id)path]; CGPath and CGMutablePath are just opaque CFType object types, and those can be added (via casting to id ) to any Cocoa container classes that are toll-free bridged to their CoreFoundation counter-parts. You can wrap CGMutablePathRef to a NSValue and store it in array. Then when needed unwrap it: //Wrap NSValue *pathValue = [NSValue valueWithPointer: path]; [array addObject:pathValue]; //Unwrap NSValue *pathValue = [array objectAtIndex: index]; CGMutablePathRef path =