So I have an NSManagedObject called Student. There is a part of my code that sometimes breaks when I call a method on a Student object e.g student.performTask()
. This gives me a EXC_BAD_ACESS which makes me believe it is a threading core data issue. However, one line before where the code breaks I access a variable from the object and there is no runtime error. So my question is: what is the difference between making a call to a variable in an NSManagedObject vs calling a method? What causes it to break for one but not for the other?
Note: the program breaks before executing a single line in the method.
Here is a snippet of my code:
let attendances = Attendance.createOrUpdateFromJsonDictionary(data!)
var seenIds = [NSNumber]()
for attendance in attendances {
let student = attendance.student
if !seenIds.contains(student.id) { //does not complain when accessing the id
seenIds.append(student.id)
let oldCurrent = student.isCurrent //does not complain or break here
student.setIsCurrent() //<- breaks here
Could the fact that attendance
is also a NSManagedObject that has student as a relationship and I am grabbing student from attendance?