tags:

views:

31

answers:

1

I am using the following array to add an object that was previously created to the favorite array:

NSMutableArray *favorites = [NSMutableArray addObject:[myList objectAtIndex:1]];

However, this code keeps crashing at runtime. I think this is not the best way to implement an array that can save and delete items; is there a better way to implement this? Is there a way to automate this process without having to add an array for every cell selected from the table?

A: 

Just write (assuming favorites array have already been created):

[favorites addObject:[myList objectAtIndex:1]];

To create new array you should use for example +arrayWithObject:

NSMutableArray *favorites = [NSMutableArray arrayWithObject:[myList objectAtIndex:1]];
Vladimir
do i need to define the index? if so how would i do it?and is the 1 for object at index the first item in the array or the name of the item in the array?
Alx
for the favorites array was created you mean if it was alloc and init coorect?
Alx
yes, if you already have mutable array instance (alloced and inited it) then you just can (and should) change it "in-place"
Vladimir
so if im having a tableindexpath should i add the index or the array the the data is taken from in the myList objectAtindex or should i do an addobject to the array? im confused now?
Alx
Now I'm confused :) What you need to store in favorites array depends on how you're going to use it in future. Adding objects looks fine for me (but you may need to make sure that favorites does not contain duplicates)
Vladimir
im asking if in order to display items that are loaded in a table should i use indexpath or addobjects form old array? i have my objects loaded in the table from mylist at index indexPath. which way is better
Alx
Personally I would add objects directly, not their indexes in main list (if you don't need those indexes for some purpose).
Vladimir
i have two levels of arrays though it loads one table view and then on user click goes to another table view which loads different values depending on the previous click which then loads a detail view unique to each cell. how would this be implemented without an index? thanks a lot for your help btw :)
Alx