1

I've read here but told to open a new question.

I have CountryEntity. It has two relations.

  • capital with a CityEntity destination—type one to one
  • cities with a CityEntity destination— type one to many.

How I should set the inverse part. Apparently only either capital or cities can have a relation with the CountryEntity.

Current issue:

enter image description here

mfaani
  • 33,269
  • 19
  • 164
  • 293

1 Answers1

1

You just... create the relationships, and give each one an inverse relationship. No special steps are needed. From your description,

  • capital would have a to-one inverse called something like capitalOf, to indicate which CountyEntity the CityEntity is capital of. If a city is not the capital, the value of the relationship would be nil.
  • cities would have a to-one inverse called something like county to indicate that the CityEntity is in the CountyEntity. This would never have a nil value.

Apparently only either capital or cities can have a relation with the CountryEntity

This isn't true, or at least it's not required by Core Data.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • About _This isn't true, or at least it's not required by Core Data._ Can you see my edit? – mfaani Dec 10 '18 at 16:54
  • Yes. You can't have two inverses **to the same relationship**. Each relationship needs its own inverse. – Tom Harrington Dec 10 '18 at 16:58
  • #facepalm! It's the first time I putting coredata to real use. I was confusing relationship with entities...So is it correct to conclude the number of relationships should always be even? – mfaani Dec 10 '18 at 17:03
  • Each relationship should have an inverse, so if you count the relationship and the inverse, it'll always be an even number. – Tom Harrington Dec 10 '18 at 17:23