[Question] remove/add item into array
Closed this issue · 3 comments
Hello,
this question might be stupid but i am a beginner.
I have no problem to retrieve data from the plist
but in my dynamicModel, i have an array, how can I do to modify this array (adding and deleting items) programmatically?
Thank you,
Arthur
Hi @mastermyx:
You can do it two ways. If you declare it as a mutable array, you can add the objects like this:
[dynamicModel.mutableArray addObject:@"AnotherObject"];
Otherwise, you'll have to do like this:
NSMutableArray *arr = [dynamicModel.array mutableCopy];
[arr addObject:@"anotherObject"];
dynamicModel.array = arr;
Does that answer your question?
Yes it does!
I thought i couldn't declare an NSMutableArray in the PlistModel class because nsmutablearray is not allowed in Plist.
Thanks!
Hi @mastermyx:
You are correct that a mutable array isn't allowed in a Plist, but this class does some stuff in the background, so you're dealing with it as a mutable array in memory, but it's persisted as an array.
Let me know if other problems come up :)