2

我之前创建了一个 ObjC 类。我怎样才能再次删除它?因为在以后的某个时候,我想用另一个版本重新创建它。

现在,如果我只是重新声明它,我会得到异常X is overriding existing Objective-C class

4

1 回答 1

3

我不知道如何在 PyObjC 中执行此操作,但用于执行此操作的 Objective-C 运行时函数应该是objc_disposeClassPair(). 搜索了一下,发现使用这个 Objective-C 运行时特性可能在 PyObjC 中不起作用:

2008 年 1 月的 PyObjC SVN 提交消息如下:http: Initial attempt of using objc_disposeClassPair. Disabled because this causes an unexpected crash. //blog.gmane.org/gmane.comp.python.pyobjc.cvs/month=20080101

有问题的代码仍在 PyObjC 源代码的当前 class-builder.m 中,第 164 行,并带有一个有趣的注释前缀:

    /*
     * Call this when the python half of the class could not be created. 
     *
     * Due to technical restrictions it is not allowed to unbuild a class that
     * is already registered with the Objective-C runtime.
     */
    int 
    PyObjCClass_UnbuildClass(Class objc_class __attribute__((__unused__)))
    {
        PyObjC_Assert(objc_class != nil, -1);
        PyObjC_Assert(objc_lookUpClass(class_getName(objc_class)) == nil, -1);

        //objc_disposeClassPair(objc_class);
        return 0;
    }

话虽如此,我从未在 Objective-C 本身中使用过它,而且我对 PyObjC 了解不多。希望这可以帮助。

于 2011-09-09T14:04:17.043 回答