Hello once again friends,

I am writing a coreData app that has a one to many relationship.

And I have the function:

@IBAction func addButton(sender: AnyObject) { ... print("\(self.timeSlotSet!.timeSlots)

") self.timeSlot!.timeSlotSet = self.timeSlotSet! print("\(self.timeSlotSet!.timeSlots)

") ... self.timeSlotSet!.calculateNumberOfItems() print("\(self.timeSlotSet!.timeSlotCount!)

") }

where the calculateNumerOfItems function is:

func calculateNumberOfItems() { timeSlotCount = timeSlots!.count }

which prints the following results to console:

Optional(Relationship 'timeSlots' on managed object (0x7ca721e0) <TimeSlotSet: 0x7ca721e0> (entity: TimeSlotSet; id: 0x7be40040 <x-coredata://39B379DC-2F28-42FE-9716-084A4769CD40/TimeSlotSet/p2> ; data: { name = nil; test = 0; timeSlotCount = 0; timeSlots = ( ); }) with objects {( )}) Optional(Relationship 'timeSlots' on managed object (0x7ca721e0) <TimeSlotSet: 0x7ca721e0> (entity: TimeSlotSet; id: 0x7be40040 <x-coredata://39B379DC-2F28-42FE-9716-084A4769CD40/TimeSlotSet/p2> ; data: { name = nil; test = 0; timeSlotCount = 0; timeSlots = ( "0x7be5a9d0 <x-coredata://39B379DC-2F28-42FE-9716-084A4769CD40/TimeSlot/p1>" ); }) with objects {( <TimeSlot: 0x7be3c2e0> (entity: TimeSlot; id: 0x7be5a9d0 <x-coredata://39B379DC-2F28-42FE-9716-084A4769CD40/TimeSlot/p1> ; data: { beginDate = "2015-12-26 12:20:43 +0000"; currentSeconds = 2; endDate = "2015-12-26 12:20:46 +0000"; timeSlotSet = "0x7be40040 <x-coredata://39B379DC-2F28-42FE-9716-084A4769CD40/TimeSlotSet/p2>"; }) )}) 0

I am having difficulty wording this... but:

I believed this line: self.timeSlot!.timeSlotSet = self.timeSlotSet! created the relationship between TimeSlotSet and TimeSlot - and added one timeSlot to TimeSlotSet's timeSlots attribute (which is an NSSet)

I also believe it is successful because when I print the timeSlotSet to console it is different after I have committed this line. (Right?)

Then why is timeSlotCount still 0? Does that not imply that timeSlots is still empty?

Also, do I have to save the timeSlot to persistent storage, or can I just save the TimeSlotSet? I want to save both. Do I have to explicitly save both? Or does saving one save both? (since they have a relationship between the two)

The end goal is that I can save many TimeSlot items to the TimeSlotSet and then iterate over its timeSlots NSSet and create algorithms for all these TimeSlot objects.

Thank you - I hope I wrote this correctly. Am I conceptually wrong anywhere? I am very confused.