Reputation: 1183
In an iPhone app, the User can create Items - each Item needs to have a CGPoint, NSString and a few integers with information about it. The User can keep adding these Items.
How can I store all these variables for each of the Items and programmatically keep adding them to a list or array or something?
I tried using a struct array but it can't hold a NSString. I tried using a NSMutableAray of a custom class, but I can only add them if I make and name them by hand.
Any suggestions, ideas? Could I use a NSDictionary?
Upvotes: 0
Views: 217
Reputation: 778
Create an Item
class, that contains your CGPoint
, NSString
, and any other piece of info you want. Then, make an NSMutableArray
and add new instances of your Item
class as you see fit. NSDictionary
and NSArray
aren't really what you're looking for.
Upvotes: 0
Reputation: 7422
Use an NSArray
or NSMutableArray
, but you have to wrap your non-object values (CGPoint
s and integers) in wrapper objects. The integers can be wrapped in NSNumber
s and the points can be wrapped in NSValue
s.
Upvotes: 2