1

I am extending an NSManagedObject class in swift and am experiencing an infinite loop when attempting to add an object to a relationship. One-To-Ones are working and yes my classes are named properly (project.class). Xcode 6.0.1. I have noticed others with this issue. Does anyone have a solution?

This is similar to this other question although this appears to be broken in Xcode 6 GM+

How to assign CoreData many-to-many relationship in Swift?

import CoreData

extension Parent {
    func addChildObject(value:ChildObject) {
        self.mutableSetValueForKey("child").addObject(value)
    }
}
Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42

1 Answers1

0

I tested this code - it is working fine. Your infinite loop must be caused by something else.

Check for setter-getter confusion with self when accessing or setting managed object attributes.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • So you are generating Swift NSManagedObject classes, using Xcode 6.0.1, iOS 8, Many-To-Many relationships and it's working fine? Can you please elaborate on what your model looks like? Others have reported this issue so perhaps its with a Many-To-Many relationship? If I generate ObjC classes and use the bridging header everything works perfectly but I would much rather use Swift if I can. "Check for setter-getter confusion with self when accessing or setting managed object attributes." Can you please explain this? – Mark McCorkle Sep 26 '14 at 11:00
  • Yes all of the above is correct. I just have too entities with a many-to-many connection. I checked the values via `NSLog` and the database. -- Put a breakpoint before the offending line (i.e. where the infinite loop starts) and then step through the code. – Mundi Sep 26 '14 at 19:57
  • Is there a possibility the naming convention could cause this in swift? (case sensitivity?) (i.e., relationship named "image" pointing to the To-Many Image object? This could be the only thing I could think of. Otherwise, I'm stumped. – Mark McCorkle Sep 26 '14 at 20:04
  • I can share my code if you would like. It took me 5 minutes to write. The name has nothing to do with it. Only rules are: not start with capital letter and no reserved word. – Mundi Sep 26 '14 at 20:10