Obj-C/Swift 项目中的致命陷阱异常 [英] Fatal trap exceptions in Obj-C / Swift project

查看:19
本文介绍了Obj-C/Swift 项目中的致命陷阱异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始将 Swift 代码集成到我的 Obj-C 项目中.一切都很顺利,但今天,当我更新到 Xcode 6.1 时,事情发生了.我从之前运行良好的 Swift 代码中收到了许多陷阱"异常.

I'm starting to integrate Swift code into my Obj-C project. Everything's been going smoothly but today, when I updated to Xcode 6.1, things hit the fan. I'm getting a number of "trap" exceptions from Swift code that was previously running fine.

第一次崩溃发生在我的 UIFont 扩展中.这是我的代码:

The first crash is in my extension of UIFont. Here's my code:

class func specialFont() -> UIFont {
    let font = UIFont(name: "FontName", size: 12.0)
    return font!
}

此代码在更新到 Xcode 6.1 之前运行良好,但现在因 EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT) 崩溃,位于 dylddyld_fatal_error: 0x1fe1608c: trap.(顺便说一句,我没有设置异常断点.)尝试继续执行程序不会生成崩溃日志,它只会进入生成该异常的无限循环.同样,代码在 Xcode 6.1 更新之前运行良好.

This code was working fine before updating to Xcode 6.1, but now crashes with EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT), at dylddyld_fatal_error: 0x1fe1608c: trap. (BTW, I don't have an exception breakpoint set.) Attempting to continue program execution doesn't generate a crash log, it just enters an endless cycle of generating that exception. Again, code worked fine before Xcode 6.1 update.

第二次崩溃特别奇怪,因为它只发生在设备上调试时,而不是在模拟器上.与上面相同的异常信息.这是崩溃的第二段代码:

The second crash is especially strange because it only happens when debugging on a device, not on the simulator. Same exception info as above. Here's the second bit of code that's crashing:

let tap = UITapGestureRecognizer(target: self, action: "didTap")
self.addGestureRecognizer(tap)

感谢您的帮助!

更新

堆栈跟踪如下:

0] dyld_fatal_error
1] dyld_stub_binder
4] Project.FileWhereCrashTriggers.methodTriggeringCrash
5] @objc Project.FileWhereCrashTriggers.methodTriggeringCrash
6] -- continued trace up to call of method crashing

这些崩溃的一个奇怪之处在于它们不会在实际代码行上触发异常,正如您从堆栈跟踪中看到的那样.它们在 dyld_fatal_error 中中断.

One weird thing about these crashes is that they don't trigger the exception on the actual line of code, as you can see from the stack trace. They break in dyld_fatal_error.

我无法上传任何控制台输出,因为该应用程序在 Xcode 中运行时从未真正崩溃 - 它无休止地调用类似于 EXC_BAD_ACCESS.我在非调试模式下触发了崩溃,然后使用 Organizer 查看了设备日志,这就是它提供的:

I can't upload any console output because the app never actually crashes while running in Xcode - it calls endlessly similar to EXC_BAD_ACCESS. I triggered the crash in non-debug mode and then looked at the device logs using Organizer and this is what it offered:

异常类型:EXC_BREAKPOINT (SIGTRAP)异常代码:0x0000000000000001, 0x00000000e7ffdefe由线程触发:0

Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000000e7ffdefe Triggered by Thread: 0

Dyld 错误消息:未找到符号:__TFSSCfMSSFT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS引用自:/private/var/mobile/Containers/Bundle/Application/4ABA71F8-A6D1-4E4B-A452-DE339065310A/Project.app/Project

Dyld Error Message: Symbol not found: __TFSSCfMSSFT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS Referenced from: /private/var/mobile/Containers/Bundle/Application/4ABA71F8-A6D1-4E4B-A452-DE339065310A/Project.app/Project

预期在:/private/var/mobile/Containers/Bundle/Application/4ABA71F8-A6D1-4E4B-A452-DE339065310A/Project.app/Frameworks/libswiftCore.dylib迪尔德版本:353.5

Expected in: /private/var/mobile/Containers/Bundle/Application/4ABA71F8-A6D1-4E4B-A452-DE339065310A/Project.app/Frameworks/libswiftCore.dylib Dyld Version: 353.5

推荐答案

经过多次试验,我能够通过在我的 swift 文件中的所有 swift 方法中使用 @objc 标记来解决这些冲突可以被我的 Obj-C 代码调用,包括初始化方法.例如,将override init(frame: CGRect) 改为@objc override init(frame: CGRect).

After experimenting more, I was able to resolved these conflicts by using the @objc marker in my swift files in all swift methods that could get called by my Obj-C code, including init methods. For example, change override init(frame: CGRect) to @objc override init(frame: CGRect).

顺便说一句:我仍然有点困惑为什么 @objc 标志在 Xcode 6.0 中不是必需的"(尽管它可能是最佳实践)但突然成为必需的在 Xcode 6.1 中.

As an aside: I'm still a bit confused by why the @objc flag wasn't 'required' (although it may have been best practice) in Xcode 6.0 but suddenly was a requirement in Xcode 6.1.

这篇关于Obj-C/Swift 项目中的致命陷阱异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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