nsarray

What is the fastest routine to convert NSArrays to C-style (double) arrays?

Hi all, I have 2 NSArray (Mutable, actually) that I am trying to convert to a C-style double array for a c routine i am passing them to. Here is my Objective-C routine: NSMutableDictionary *childDictionary = [myParentDictionary objectForKey:resort_code]; latitudeArray = [childDictionary objectForKey:@"lat"]; longitudeArray = [childDic...

Encode NSArray or NSDictionary using NSCoder

I was wondering whether or not it is possible to use the NSCoder method: - (void)encodeObject:(id)objv forKey:(NSString *)key to encode either an instance of NSArray or NSDictionary. If not how do you go about encoding them? I am trying to use NSKeyedArchived / NSKeyedUnarchiver to send data between phones using GameKit. I tried it an...

how to create an "array of selectors" in objective-c

Hi, i'm using the iphone sdk (3.0) and i'm trying to create an array of selectors to invoke a variety of methods within one class. Obviously, I'm doing something wrong (I think @selector isn't considered a class and so stuffing them into an NSArray isn't working). I tried this, but it's obviously wrong. Is there a simple way to have...

After using an NSArray *sort* method, am I responsible for releasing the returned array.

Hi, Im used to c programming where im responsible for freeing everything, and this objective c funky stuff is throwing some spanners in the work. I am using the below code. NSArray *b = [a allObjects]; NSArray *c = [b sortedArrayUsingDescriptors:sortDescriptors]; Who's responsible for releasing "b" and "c". For the record, "a" is a NS...

Need to convert NSData to NSArray

I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to convert this to an NSArray. Can anyone help me? I am refactoring a method that currently does a synchronous request to the URL, using arrayWithContentsOfURL: to get the NSArray. Thanks!! ...

What is leaking in this statement using replaceObjectAtIndex

Instruments tells me the following line from the code below is leaking: I can't figure out how to fix this leak. [self.selectedElement.usrAdvancedBuyingPercents replaceObjectAtIndex:selectedRow withObject:[numberFormatter stringFromNumber:percentage]]; - (IBAction) simpleMarginSliderValueChanged:(UISlider *)sender { NSDecimalNumber...

Better alternative for checking existence of NSDictionary's key in NSArray?

Hi, I have an NSArray of NSDictionaries. I need to check if there's at least one occurrence of an object for a key of the NSDictionary in the NSArray. I do this by using int i; for (i=0;i< [myArray count];i++) { if ([[[myArray objectAtIndex: i] objectForKey: myKey] isEqualToString: myString]) { found = YES; break; ...

NSArray - check if objects are in an array?

I have 2 arrays. One is a large static group of 600 objects, the other is a small varying group of 10 objects. I want to take any common objects between the two groups and put them in a new array. So lets say the large group contains 600 objects named 1 to 600. The smaller group contains 9 objects: 1, 2, 3, 4, 5, 6, a, b, c. I want to ...

NSArray question - \n\t\t being added to the end of strings?

My strings are fine, but when they get added to an array a weird grouping of "\n\t\t" gets added to the end. So the string "Apple", becomes "Apple\n\t\t" when I look at the array description. Whats the deal with that? and how do I fix it? Addition: Its XML code. It seemed like [currentPlace appendString:string]; would get the right pa...

NSDictionary to NSArray?

Hey all, i have a NSDictionary which looks like: { "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } To use this Dictionary Items in a Table View i have to transfer it to a NSArray, am i right? So i try: NSDictionary *dict = [myDict objectForKey:@"items"]; for (id item in dict) { [_myArray addObject:[dict objectForKey:item]]; } ...

Sorting an NSArray

I have an NSArray as follows: NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:filePath]; The files at filePath are: 11.thm, 12.thm, 13.thm,...,Text_21.thm, Text_22.thm, Text_23.thm,... I would like to sort the NSArray in the order: 13.thm, 12.thm, 11.thm,..., Text_23.thm, Text_22.thm, Te...

NSarray release

Hello everybody, If i declare an NSArray with alloc & retain in single sentence then should i release the NSArray object twice (i.e. [arrayObject release] 2 times) ? ...

Binding an NSTableView to an NSMutableArray

Here is this question version with images. I can't post it because of Stackoverflow policy concerning spam. Hello! I'm learning Cocoa, and I've got a problem: I would like to bind the content of an NSMutableArray to an NSTableView, with bindings. I read many documentations about them, but I can't manage to make them work (nothing is di...

Parsing text file into NSArray but how do I extract it?

I have this code NSArray *wordListArray = [[NSArray alloc] initWithArray: [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”sowpods” ofType:@”txt”] encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@”\n”]]; My question is how can I extract this text and update a label in a Scrollvi...

Is there a trick to see NSString values in an NSMutableArray in Xcode debugger?

When I debug, I never get the value of an NSString inside of an array. All I see are cryptic symbols, probably memory addresses of something like 0x1dc3753. I dig into all the stuff and expand everything, but no humanly readable value at all. Not really useful at all. How do you go about this (besides NSLogging everything)? ...

parsing txt from array to UILabel

Hello All, I'm actually starting to loose the will to live, this piece of code is driving me nuts! I'm trying to get the content of mathspractice.txt into *myLabel I'm using an array which is: -(void)loadText { NSArray *wordListArray = [[NSArray alloc] initWithArray: [[NSString stringWithContentsOfFile:[[NSBundle mainBundle...

From NSArray to UILabel

My code compiles fine but doesn't show the text from mathspractice.txt -(void)loadText { NSBundle *bundle = [NSBundle mainBundle]; NSString *textFilePath = [bundle pathForResource:@"mathspractice" ofType:@"txt"]; NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath]; NSArray *mathsPracticeTextArray = [[NSArray al...

warning: assignment from distinct Objective-C type

I've looked though al the previous questions and answers on this error but I can't figure out what I'm doing wrong. Can anyone help? @synthesize myScrollView; @synthesize mathsPracticeTextArray; -(void)loadText { NSBundle *bundle = [NSBundle mainBundle]; NSString *textFilePath = [bundle pathForResource:@"mathspractice" ofType:@...

How do I set an array with another Array?

@property (nonatomic, retain) NSMutableArray *filteredListContent; ---- @synthesize filteredListContent; - (void)applicationDidFinishLaunching:(UIApplication *)application { NSMutableArray *test = [[NSMutableArray alloc] init]; [test addObject:@"test string"]; [filteredListContent addObjectsFromArray:test]; N...

The app crashes when it hits this line... any ideas?

I am trying to build a UITableView which just goes really weird? Here is the line it crashes at: bookmarksList = [[NSArray alloc] initWithContentsOfFile:[self saveFilePath]]; I have the bookmarksList declaired as an NSArray in the header file, so thats all good. The method saveFilePath is as follows and works for actually saving a fil...