启用ARC的项目具有非ARC静态库

时间:2012-11-11 20:14:07

标签: objective-c cocoa automatic-ref-counting

我有一个启用ARC的Mac项目,启用了非ARC的框架,所有编译都很好但是一旦运行,非ARC框架就会显示一个表单,但是当你点击一个按钮时,就会抛出一个错误......

2012-11-10 23:32:11.191 TestApp[20691:303] -[__NSCFType next:]: unrecognized selector sent to instance 0x101c13070
2012-11-10 23:32:11.193 TestApp[20691:303] -[__NSCFType next:]: unrecognized selector sent to instance 0x101c13070
2012-11-10 23:32:11.198 TestApp20691:303 doesNotRecognizeSelector:] + 186
3 CoreFoundation 0x00007fff8e63a5ce forwarding + 414
4 CoreFoundation 0x00007fff8e63a3b8 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8ff78a59 -[NSApplication sendAction:to:from:] + 342
6 AppKit 0x00007fff8ff788b7 -[NSControl sendAction:to:] + 85
7 AppKit 0x00007fff8ff787eb -[NSCell _sendActionFrom:] + 138
8 AppKit 0x00007fff8ff76cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
9 AppKit 0x00007fff8ff76521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
10 AppKit 0x00007fff8ff75c9c -[NSControl mouseDown:] + 820
11 AppKit 0x00007fff8ff6d60e -[NSWindow sendEvent:] + 6853
12 AppKit 0x00007fff8ff69744 -[NSApplication sendEvent:] + 5761
13 AppKit 0x00007fff8fe7f2fa -[NSApplication run] + 636
14 AppKit 0x00007fff8fe23cb6 NSApplicationMain + 869
15 AppSim 0x00000001000026f2 main + 34
16 libdyld.dylib 0x00007fff97c6c7e1 start + 0
17 ??? 0x0000000000000003 0x0 + 3

将主项目转换为非ARC的问题是......导致问题的原因是什么,以及如何绕过它?

我宁愿不将我现有的项目转换为使用非ARC ......

重现问题的步骤......

下载“OS X Lion示例项目,约250 KB”

https://github.com/eternalstorms/ESSVideoShare-for-OS-X-Lion

将主项目转换为ARC,指向以...开头的行[yt uploadVideoAtURL:[NSURL fileURLWithPath到您拥有的任何mov文件,然后运行。

点击取消或登录会导致错误...

2 个答案:

答案 0 :(得分:2)

您的示例代码有内存泄漏:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    ESSYouTube *yt = [[ESSYouTube alloc] initWithDelegate:self
                                             developerKey:@""];
    [yt uploadVideoAtURL:[NSURL fileURLWithPath:@"/path/to/mov"]];
}

yt永远不会被释放。

当您通过添加release或转换为ARC来插入该泄漏时,您将收到崩溃,因为在UI处于已释放的情况下ESSYouTubeESSYouTubeWindowController实例已取消分配还在屏幕上。

示例代码需要修复,ESSYouTube应该在其屏幕上显示UI时自行保留,或者在解除分配时删除其UI。

答案 1 :(得分:1)

您可以拥有一个包含ARC和非ARC资产的项目。如果您还没有,我会设置任何不支持ARC的类,以便不使用ARC进行编译。请参阅此处:How can I disable ARC for a single file in a project?