Swift:exc_breakpoint(code = exc_arm_breakpoint subcode = 0xdefe)onForForSegue
出于某种原因,当达到performSegueWithIdentifier行时出现此错误。Swift:exc_breakpoint(code = exc_arm_breakpoint subcode = 0xdefe)onForForSegue
我有这样的代码:
if let storedAPIKeychain: AnyObject = dictionary.objectForKey("api_key") {
println(storedAPIKeychain)
//This is the line that causes the problems.
performSegueWithIdentifier("skipBrandSegue", sender: self)
}
的的println()工作正常,并输出正确的信息。
我试图通过storedAPIKeychain与SEGUE一起:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if segue.identifier == "skipBrandSegue" {
// Create a new variable to store the instance of the next view controller
let destinationVC = segue.destinationViewController as brandsViewController
destinationVC.storedAPIKey = storedAPIKeychain!
}
}
而且我认为他可能会出现的问题。然而,当我将该行更改为:
destinationVC.storedAPIKey = "someAPIplaceholder"
我也遇到同样的错误。
有人可以告诉我这个错误是什么以及如何解决它。谢谢。
编辑:错误的屏幕截图:
的动态转换类无条件表明*施放失败,因为变量不能转换为另一种类型。
在你的代码中,我看到一个投只有在这行:
let destinationVC = segue.destinationViewController as brandsViewController
这意味着目标视图控制器不是brandsViewController
一个实例。
要解决此问题:
- 检查接口生成器,为目标视图控制器的自定义类属性正确设置为
brandsViewController
- 检查SEGUE实际上指向一个视图控制器
如果以上都没有解决该问题,请在该行设置断点并检查目标视图控制器的实际类型。注意:按照惯例,在swift中,所有类型名称都以大写字母开头,而函数,变量和小写属性。如果您想让您的代码对其他快速开发人员可读,建议您遵循该惯例(将brandsViewController
重命名为BrandsViewController
)
@antonios答案应该可以解决您的问题。中断是由于对象未被投射(找到并分配)。
只是一个侧面说明:你将有一些问题,与这条线:
if let storedAPIKeychain: AnyObject = dictionary.objectForKey("api_key")
特别是如果你希望从中得到一个字符串并传递ViewControllers之间?
把它作为一个字符串强制转换,创建一个全局作用域变量,然后将其赋值给该变量使用 - 然后处理会更容易。
var globalVariable = "" //add this line at the top, just before your class declaration.
if let storedAPIKeychain = dictionary.objectForKey("api_key") as? String {
self.globalVariable = storedAPIKeychain
}
这帮了我一大堆。 – DannieCoderBoi 2015-02-08 05:40:43
谢谢,我是Swift/Xcode的新手,我忘了添加Segue。 – DannieCoderBoi 2015-02-08 05:40:25