自定义Xcode IDE插件错误:“无法找到名为...的类” [英] Custom Xcode IDE Plugin error: "Could not find class named..."

查看:136
本文介绍了自定义Xcode IDE插件错误:“无法找到名为...的类”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了自己的自定义Xcode .ideplugin,以将自定义对象添加到Xcode的对象库窗格。我有我的自定义对象模板基于一个类,我称为IBMyCustomObject,其依次有一个类的我的运行时类名称MyCustomObject(运行时类名称是将在运行时被加载Xib文件时实例化的类的名称) 。



经过大量的研究,我成功地得到了这个工作。我现在可以将自定义对象从对象库窗格拖放到Xib文件,在检查器窗格中设置对象属性,其他一切正常。唯一的问题出现在编译时,Xcode的 ibtool 在编译Xib文件时给我以下错误:

 异常名称:NSInvalidArgumentException 
异常原因:找不到类名为MyCustomObject

这是完整的例外回溯日志:

 异常回溯:
0的CoreFoundation 0x0226d6d8 __exceptionPreprocess
1. libobjc.A.dylib 0x01fe98b6 objc_exception_throw
2的CoreFoundation 0x022fd721 - [NSException提高]
3? 0x000116b8 [IBCocoaTouchToolObjectPackage initWithRequest:]
4.? 0x00010597 [IBCocoaTouchTool .cxx_destruct]
5. 0x0000b63d [IBCocoaTouchTool compileNibForRequest:minimumCompatibility:layoutInfo:]
6. IBFoundation 0x00362c51 __72- [IBMessageReceiveChannel deliverMessage:toTarget:withArguments:结果:] _ block_invoke
7. IBFoundation 0x00362996 - [IBMessageReceiveChannel deliverMessage:toTarget:withArguments:结果:]
8. IBFoundation 0x00362673 __80- [IBMessageReceiveChannel runBlockingReceiveLoopNotifyingQueue:notifyingTarget:] _ block_invoke
9. libdispatch.dylib 0x029c2444 _dispatch_barrier_sync_f_slow_invoke
10. libdispatch.dylib 0x029d34b0 _dispatch_client_callout
11. libdispatch。 dylib 0x029c1766 _dispatch_main_queue_callback_4CF
12的CoreFoundation 0x022d2b6e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13的CoreFoundation 0x022137eb __CFRunLoopRun
14的CoreFoundation 0x02212bf3 CFRunLoopRunSpecific
15的CoreFoundation 0x02212a0b CFRunLoopRunInMode
16.基金会0x01c1fe55 - [NSRunLoop (NSRunLoop)runMode:beforeDate:]
17. 0x0003ac67 [IBAbstractCocoaTouchTool startServingReceiveChannel:]
18.? 0x0003ad62 [IBAbstractCocoaTouchTool startServingSocket:]
19.? 0x0003aec7 [IBAbstractCocoaTouchTool protocolCapabilities]
20. 0x0001053e [IBCocoaTouchTool .cxx_destruct]
21. libdyld.dylib 0x9313d725 start
例外信息:{
}

有关如何让Xcode(更具体地说,ibtool)知道MyCustomObject类,以便它可以在编译时找到它的任何想法?我试过很多事情,包括将MyCustomObject放置在一个框架中,并在运行时加载包,但没有什么工作。如果我将IBMyCustomObject的runtimeClassName替换为NSMutableDictionary(或任何其他Foundation或UIKit类)而不是MyCustomObject,一切都能正常工作,但我真的需要使用自己的MyCustomObject类。



PS:对于有兴趣开发类似插件的用户,我将在 sensiblecocoa.com (该框架使用

解决方案

好吧,结果是Xcode(更具体地说,ibtool)产生一个在编译期间称为Interface Builder Cocoa Touch Tool的全新过程,这解释了为什么加载 MyCustomClass 包没有任何效果。我考虑的一个可能的解决方案是使用dylib注入注入 MyCustomClass 库到新生成的进程,但我发现的技术没有足够可靠的稳健和稳定我最终最终使用 NSMutableDictionary 而不是 MyCustomClass ,这完全编译。然后我在对象所有者类中使用setter属性方法将加载的 NSMutableDictionary 转换为 MyCustomClass ,然后手动分配所有字典键到它们各自的属性。如前所述,我将在 sensiblecocoa.com 博客页面上发布所有插件开发细节。


I've developed my own custom Xcode .ideplugin to add a custom object to Xcode's Object Library pane. I have my custom object template based on a class I called IBMyCustomObject, which in turn has a runtimeClassName of a class I called MyCustomObject (a runtime class name is the name of the class that will be instantiated at runtime when the Xib file is loaded).

After tons of research, I've been able to successfully get this working. I can now drag and drop my custom object from the Objects Library pane to Xib files normally, set the object properties in the inspector pane, and everything else is working great. The only problem comes at compile time, where Xcode's ibtool gives me the following error when the Xib file is compiled:

Exception name: NSInvalidArgumentException
Exception reason: Could not find class named MyCustomObject

And here is the full exception backtrace log:

Exception backtrace: 
  0. CoreFoundation           0x0226d6d8 __exceptionPreprocess
  1. libobjc.A.dylib          0x01fe98b6 objc_exception_throw
  2. CoreFoundation           0x022fd721 -[NSException raise]
  3. ???                      0x000116b8 [IBCocoaTouchToolObjectPackage initWithRequest:]
  4. ???                      0x00010597 [IBCocoaTouchTool .cxx_destruct]
  5. ???                      0x0000b63d [IBCocoaTouchTool compileNibForRequest:minimumCompatibility:layoutInfo:]
  6. IBFoundation             0x00362c51 __72-[IBMessageReceiveChannel deliverMessage:toTarget:withArguments:result:]_block_invoke
  7. IBFoundation             0x00362996 -[IBMessageReceiveChannel deliverMessage:toTarget:withArguments:result:]
  8. IBFoundation             0x00362673 __80-[IBMessageReceiveChannel runBlockingReceiveLoopNotifyingQueue:notifyingTarget:]_block_invoke
  9. libdispatch.dylib        0x029c2444 _dispatch_barrier_sync_f_slow_invoke
 10. libdispatch.dylib        0x029d34b0 _dispatch_client_callout
 11. libdispatch.dylib        0x029c1766 _dispatch_main_queue_callback_4CF
 12. CoreFoundation           0x022d2b6e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
 13. CoreFoundation           0x022137eb __CFRunLoopRun
 14. CoreFoundation           0x02212bf3 CFRunLoopRunSpecific
 15. CoreFoundation           0x02212a0b CFRunLoopRunInMode
 16. Foundation               0x01c1fe55 -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
 17. ???                      0x0003ac67 [IBAbstractCocoaTouchTool startServingReceiveChannel:]
 18. ???                      0x0003ad62 [IBAbstractCocoaTouchTool startServingSocket:]
 19. ???                      0x0003aec7 [IBAbstractCocoaTouchTool protocolCapabilities]
 20. ???                      0x0001053e [IBCocoaTouchTool .cxx_destruct]
 21. libdyld.dylib            0x9313d725 start
Exception info:{
}

Any ideas on how can I have Xcode (more specifically ibtool) know about the MyCustomObject class so that it could find it at compile time? I've tried many things, including placing MyCustomObject in a framework and loading the bundle at runtime, but nothing worked at all. If I replace IBMyCustomObject's runtimeClassName with NSMutableDictionary (or any other Foundation or UIKit class) instead of MyCustomObject, everything works perfectly, but I really need to use my own MyCustomObject class instead.

P.S.: For everyone interested in developing similar plugins, I'll be posing all my findings in a detailed blog post on sensiblecocoa.com (the framework using the plugin) once I have everything figured out.

解决方案

Ok, it turns out that Xcode (more specifically ibtool) is spawning an entirely new process called "Interface Builder Cocoa Touch Tool" during compile time, which explains why loading the MyCustomClass bundle had no effect. One possible solution to this that I considered was using dylib injection to inject the MyCustomClass library into the newly spawned process, but none of the techniques I found were reliable enough for robust and stable production code.

I finally ended up using NSMutableDictionary instead of MyCustomClass, which compiled perfectly. I then used a setter property method in the object owner class to convert the loaded NSMutableDictionary into MyCustomClass, then manually assigned all the dictionary keys to their respective properties. As I said before, I'll be posting all the plugin development details on the sensiblecocoa.com blog page.

这篇关于自定义Xcode IDE插件错误:“无法找到名为...的类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆