views:

66

answers:

1

The user will have a static list of items to choose from. Using a Picker View they will choose one of the items and then select how many of them they want.

Whats the best way to save this in core data? A Struct?

struct order {
    NSInteger item;
    NSInteger numberOf;
};

Or some sort of relationship?

Many Thanks

+1  A: 

In Core Data you would create an entity to model the users choices.

Assuming the item is just a name then you would have an entity something like this:

ChoiceEntity{
    itemName=string;
    quantity=int;
}

If items have their own entity, it would look like this:

ChoiceEntity{
    quantity=int;
    item <<--(required,nullify)--> ItemEntity;
}

ItemEntity {
    // ... attributes of items. 
    choices <--(optional, cascade)-->> ChoiceEntity;
}

For simple data without relationships, you can think of Core Data entities as simple structs. (In fact, under the hood, that's what they are.)

TechZen
So for example if ChoiceEntity was one item on an order would I put ChoiceEntity as a to - many relationship in my OrderEntity. If that makes sense?So a customer could put in a single order:Apples x 2,Bread x 1,Chocolate x 10
Daniel Granger
Yes, that sounds right.
TechZen