Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Swift _Class to-many accessors recurse infinitely #227

fritza opened this Issue · 5 comments

4 participants


Consider entity Passer, which is one-to-many with entity Games. mogenerator creates these extensions in _Passer.swift:

extension _Passer {

    func addGames(objects: NSSet) {

    func removeGames(objects: NSSet) {

    func addGamesObject(value: Game!) {

    func removeGamesObject(value: Game!) {

When I get to the line

            newGame.passer = passer

… Core data hits the inverse, the @NSManaged games set.

This results (surprisingly rapidly — Swift is beginning to live up to its potential for speed) in a stack 112,165 frames deep, recurring through addGamesObject(Game!).

I infer that NSManagedObject implements the to-many Set proxies in terms of the already-synthesized (just never declared) add{Relationship}Object (etc.) methods. That’s what I see in the disassembly.

I commented the to-many extension out, and the application runs as expected. I imagine this is a Simple Matter Of Programming™ with the Swift template, and I’d offer a pull request, but there are so many damn branches, I don’t know which I should work against.

Anyone else seeing this?


Can confirm, not sure what the side effect of removing the convenience methods will be except for a lack of convenience maybe

@rokgregoric rokgregoric referenced this issue from a commit in rokgregoric/mogenerator
@rokgregoric rokgregoric Removed to-many accessors from swift template. [#227] fc4c1df

My app used these methods so the deletion of the accessors broke me. I had to restore them all from git and move them into my human files to resume work.

I was seeing a crash/hang involved in ordered to-many relationships, but the workaround there was not to set an inverse relationship. That of course caused build warnings but it ran without error.

Are you saying there is a direct way in Swift to use to-many and ordered to-many relationships without these accessors (or their proxy sets which were also removed)?


I just commented out those extensions and got several "unresolved identifier" errors on calls like:


The errors occur whether the to-many relationship is ordered or not.

So I don't think those accessors are synthesized in Beta 6. In other words, it looks like we need them — unless I'm missing something here. :)


The accessors are not synthesized .. but in reality you don't need them .. you can access the NSSet or NSOrderedSet and update it.

But actually I agree it's nice to have them around .. so:

Would this solve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.