Echizzle
Echizzle

Reputation: 3459

Core data NSOrderedSet in iOS 9

I noticed that in iOS 9 (in Objective C at least) that when a one-to-many core data relationship is established that the parent entity no longer contains an NSOrderedSet of the child one.

I have a recipe app and the recipe to ingredients relation is one to many yet the ingredients now appears like this in the recipe file

@property (nullable, nonatomic, retain) Ingredient *ingredients;

used to be...

@property (nonatomic, retain) NSOrderedSet *ingredients;

When I try to access this in the number of rows in section method it doesn't work like it used to in older versions of iOS. Ideally I want to return the number of ingredients in any given recipe like...

return self.recipe.ingredients.count

^^This doesn't work anymore although did in my older projects

Screenshots of data model

Any ideas? Thanks!

relationships

ingredient

recipe

Upvotes: 0

Views: 355

Answers (1)

Jody Hagins
Jody Hagins

Reputation: 28419

I wish you had selected the "ingredients" relationship in the picture of the Recipe entity. However, it doesn't matter much because I can tell from the little icon next to the "ingredients" relationship that it is a to-one relationship (also the little line going from Recipe to Ingredient only has one arrow at the end).

You need to select the "ingredients" relationship, and then in the little editor on the right, make sure you select to-many. You will also need to click on the check box for "Ordered" if you want an ordered relationship, otherwise the relationship will be an unordered NSSet.

Upvotes: 1

Related Questions