2

先ほど ObjC クラスを作成しました。どうすればまた削除できますか? 後で、別のバージョンで再作成したいからです。

今、再宣言すると、例外が発生しますX is overriding existing Objective-C class

4

1 に答える 1

3

I don't know how to do this in PyObjC, but the Objective-C runtime function for doing this should be objc_disposeClassPair(). Searching around a bit yielded an indication that using this Objective-C runtime feature might not work in PyObjC:

A PyObjC SVN commit message from January 2008 reads: Initial attempt of using objc_disposeClassPair. Disabled because this causes an unexpected crash. http://blog.gmane.org/gmane.comp.python.pyobjc.cvs/month=20080101

The code in question is still in the current class-builder.m of PyObjC's source in line 164ff and is prefixed with an interesting comment:

    /*
     * 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;
    }

That being said, I never used this in Objective-C itself and I don't know much about PyObjC. Hope this helps.

于 2011-09-09T14:04:17.043 に答える