SOLVED <module> error: X is overriding existing Objective-C class



  • Occasionally I'll try to make a tool that subclasses a vanilla or an Objective-C object like so:

    class MyWindow(vanilla.Window):
        ...
    
    class MyObject(NSObject):
        ...
    

    and either I'll get this error on the first call in RoboFont... or, more strangely, it might work once, and THEN I'll get the following error:

    <module> error: MyWindow is overriding existing Objective-C class
    

    My question is: Why am I getting this error, and is there a way to subclass a vanilla object in RF?



  • Thanks, @frederik! I had no idea about the metaclass before, seems pretty useful for debugging.


  • admin

    For NSObjects or any subclass of such a NSObject (that is any AppKit object) there can only be one with the same name during a runloop.

    Try to save your nsObjects in a separate file and import the required classes. Try to give a good unique name: <ToolInitials><Name> fe CFWindow.

    As a last resort you can use the embedded helper that renames the class.

    import AppKit
    from lib.tools.debugTools import ClassNameIncrementer
    
    class MyObject(AppKit.NSObject, metaclass=ClassNameIncrementer):
       pass
    

    but never use ClassNameIncrementer in production code, only during testing.

    good luck!


Log in to reply