Adding an object to an NSSet in a many-to-many database

I have a basic data structure with restaurants and atmospheres where a restaurant can have many atmospheres and there can be many restaurants in the atmosphere. So I made a two-two relationship, both were inverse to themselves, as stated in the Apple Documentation, forming a many-to-many relationship.

However, I am having problems adding objects to the created sets. For example, when I use such code,

Atmosphere *atmosphere = [Atmosphere atmosphere:aId inManagedObjectContext:context]; [restaurant addAtmospheresObject:atmosphere]; 

it crashes with a strange error:

 EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) 

Has anyone come across this please?

+6
source share
1 answer

It looks like you did not correctly create your atmosphere object. Try the following:

 Atmosphere *atmosphere = [NSEntityDescription insertNewObjectForEntityForName:@"Atmosphere" inManagedObjectContext:context]; // further configuration if (restaurant) { [restaurant addAtmospheresObject:atmosphere]; } 
+12
source

Source: https://habr.com/ru/post/912656/


All Articles