The application scenario is as follows, each user can set multiple reminders, when deleting a user, you should delete the relevant reminders, and delete a reminder, you should delete the reminder from the user information.
Then profile should create a relationship.
And reminder should be built like relationship.
When adding reminder to a profile, to set the relationship of 2 objects, see the following example code:
if(Profile! =Nil) {Reminder.profileid=Current_profile.pid; Reminder.contents= @[@"First Contents"]; Reminder.type=[NSNumber NumberWithInt:self.type]; Reminder.repeattype=[NSNumber numberwithint:erepeattypeweekly]; Reminder.profile=Profile ; Nsmutableset*reminderset =[[Nsmutableset alloc] initWithSet:profile.reminder]; [ReminderSet Addobject:reminder]; Profile.reminder=ReminderSet; }
After the above process, when you delete a profile from the database, the associated reminder will be automatically deleted.
It is important to note that when you set an object's relationship delete rule, it refers to what to do with this relationship property when you delete this object.
IOS CoreData Cascade Delete