nsarray

NSArray objectAtIndex is not working. Please help

NSArray* address = [NSArray arrayWithArray:[detailItem addressArray]]; NSLog(@"address = %@", address); NSString* addressToString = @""; int arrayCount = [address count]; for (int i = 0; i < arrayCount; i++) { addressToString = [addressToString stringByAppendingString:[address objectAtIndex:i]]; if (i == arrayCount -1) { ...

An Important Question About NSDictionaries

I have an NSDictionary with NSStrings Some of the valueForKey:@"Key" have no entry so it's (null) NSMutableString* addressDictionaryToString = [NSMutableString string]; // use mutable string! for (NSDictionary* item in address) { // use fast enumeration! [addressDictionaryToString appendFormat:@"%@, %@, %@, %@", [...

Objective C - Initializer element is not constant

Really beginner question here. I have an NSArray of images which in its last line has an error in Xcode saying that the "initializer element is not constant". any help please? ...

iPhone ... If you have an NSArray of NSMutableDictionaries, does the Array hold a ref to the dict or a "copy"?

Okay, coming from a perl background I am used to Arrays holding refs to Hashes (Dictionary in iPhone parlance). What I would like to know is this: If I have a NSArray of NSMutableDictionaries. Say I added the following NSMutableDictionary to an NSArray: [theArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys: timest...

formatting array into plist.

I have a JSON return being formatted and saved into a plist, it looks like the following: I need it to have the following format: I'm missing something in the saving of the array so I can add the "Rows" below the Root and "Item 0, etc" under the profile, any ideas? Here is my code: NSURL *url = [NSURL URLWithString:@"http://1...

Comparing values In 2 different NSArray objects

I have 2 NSArray's that are holding values... For example NSArray 1 has values 1 2 4 in it and NSArray 2 has values 1 2 4 5 6 in it. How can I write code to compare these 2 arrays to get the following information... Count the values that are the same (so in this case 3) and count the values that are not the same (in this case 2). I ...

Need clarification on addObjectsFromArray function

I have the following code (both items and itemsCopy are NSMutableArray's): //DO: populate items w/ 30 elements [self.itemsCopy addObjectsFromArray:self.items]; //DO: remove all elements in items Results Begin Pass 1: itemsCopy = 0 items = 30 End Pass 1: itemsCopy = 30 items = 0 Begin Pass 2: itemsCopy = 0 items = 30 End Pass 2: it...

How to store an NSArray in an NSDictionary?

I'm trying to teach myself but am struggling with how to store something like an NSArray inside an NSDictionary. Let's say hypothetically you had a NSDictionary for recipes: Let's say the NSDictionary had keys like: Spaghetti, Fettucine Alfredo, Grilled Chicken Salad And the NSDictionary had an NSArray which was simply a list of ingr...

addObjectsFromArray vs. mutableCopy

I have the following code: self.itemsCopy = [self.items mutableCopy]; //[self.itemsCopy addObjectsFromArray:self.items]; NSLog(@"------- BEFORE APPEND --------"); NSLog(@"items count: %d",[items count]); NSLog(@"itemsCopy count: %d",[itemsCopy count]); My results are: ------- BEFORE APPEND -------- items count:...

indexOfObject vs. indexOfObjectIdenticalTo

What is the difference between these two NSArray methods? ...

many retains placed on NSURL when using arrayWithContentsOfURL

I am creating an NSArray from a URL that points to a plist NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[1]" content = [NSArray arrayWithContentsOfURL:_url]; NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[10]" I'm completely at a loss as to why this is occurring. Let me know if you need further informat...

Sorting an NSArray by a key-value relationship that is 2 levels deep

I have an NSArray of UILocalNotification objects that I need to sort according to a key within the UILocalNotification's userInfo property, which is an NSDictionary. I know how to sort NSArrays by a value that is one level deep, e.g., a key within an array of NSDictionaries, but two levels deep I'm lost. I want to do something like this ...

Array in Objective C (iPhone)

Hello, I want to ask about the NSArray in objective C. I want to create a dynamic array as I don't know about the size of the array. And I also want to insert some of the data to the array. However, I don't know how to decl, init and insert the element in to the array. The following is the C++ version. I want to create a empty array A...

Checking for Duplicates NSArray

Can someone help me with some code to check for duplicates in an NSArray for obective C. I did what I want in vb.net but the translation is hard for me. 'True means no duplicates' Public Shared Function checkDuplicate(ByVal list As ArrayList) As [Boolean] Dim [set] As New HashSet(Of Integer) For i As Integer = 0 To list.Count - ...

Should I set up a protocol for Objective C array objects to avoid a compiler warning?

I have a class, let's call it ABC, with an NSArray *objects property, and the objects in the NSArray can be one of two different classes, X and Y. Both X and Y have a path property, but the compiler doesn't know this. Therefore, even though ABC will always find the path property on my array objects, I get compiler warnings on my code -...

Iterating Through an NSArray

Can someone help me fix my code here. I am trying to do something simple iterate through the whole array that has NSString's in it convert them to NSIntegers and assign them to a NSInteger variable. for (NSInteger *itemF in myNSArray) { //WHERE "slotA" is an NSInteger and "itemF" is stored as an NSString and I wanna conver to NSI...

Initializing NSArray And Adding An NSInteger To It

I am having problems initalizing an NSArray and adding integers to it here is my code below which I commented in what I am trying to accomplish can someone help me fix it? my app crashes when adding an object, but I dont know if I am clearing the array correctly either. //CREATE AND INITIALIZE AN ARRAY NSArray *ticket; ...

make array out of string with variable number of spaces in Objective-C

This is the code that I would use if it was always single spaces in between words. Since I have multiple spaces in between some words how can my code be changed to remove the extra spaces when using componentsSeparatedBySring. I'm new to OBjective-C so any help would be greatly appreciated! Here is my code: NSString *myString = @"One Tw...

How to tell how may unique elements there are an NSArray

I've got an array (actually a mutable array) of NSStrings, and I want to find out how many unique elements the are in the array. For instance, say the array is made up of: Orange, Lemon, Lemon, Orange, Lemon Then there are just two unique elements (Orange and Lemon). And this array: Paul, Steve, John, Harry, Paul, John ..has four ...

Easiest way to populate array from custom class?

Say you have a class Person (with name, age, etc), and an array called PeopleArray which has several individual Person's. What's the easiest way of extracting each Person's name (for instance) and putting it into an array. Psuedocode is: nameArray = every Person's name, from the array PeopleArray ...