2014-11-04 61 views
1

我有一个简单的iOS测试应用程序在swift中。我在故事板的开头添加了一个额外的视图控制器,并创建了一个LoginViewController类:UIViewController我已将View Controller设置为自定义类LoginViewController,并更改了属性以使其成为初始视图控制器。添加新的视图控制器时Swift dynamic cast失败

我还添加了一个简单的按钮,这是我的应用程序的其余部分。

现在,当我开始我的应用程序在模拟器,它立即用下面的崩溃:

libswiftCore.dylib`swift_dynamicCastClassUnconditional: 
0x10cc3f9e0: pushq %rbp 
0x10cc3f9e1: movq %rsp, %rbp 
0x10cc3f9e4: testq %rdi, %rdi 
0x10cc3f9e7: je  0x10cc3fa1e    ; swift_dynamicCastClassUnconditional + 62 
0x10cc3f9e9: movabsq $-0x7fffffffffffffff, %rax 
0x10cc3f9f3: testq %rax, %rdi 
0x10cc3f9f6: jne 0x10cc3fa1e    ; swift_dynamicCastClassUnconditional + 62 
0x10cc3f9f8: leaq 0xb5109(%rip), %rax 
0x10cc3f9ff: movq (%rax), %rax 
0x10cc3fa02: andq (%rdi), %rax 
0x10cc3fa05: nopw %cs:(%rax,%rax) 
0x10cc3fa10: cmpq %rsi, %rax 
0x10cc3fa13: je  0x10cc3fa2d    ; swift_dynamicCastClassUnconditional + 77 
0x10cc3fa15: movq 0x8(%rax), %rax 
0x10cc3fa19: testq %rax, %rax 
0x10cc3fa1c: jne 0x10cc3fa10    ; swift_dynamicCastClassUnconditional + 48 
0x10cc3fa1e: leaq 0x36b3d(%rip), %rax  ; "Swift dynamic cast failed" 
0x10cc3fa25: movq %rax, 0xb4a2c(%rip)  ; gCRAnnotations + 8 
0x10cc3fa2c: int3 
0x10cc3fa2d: movq %rdi, %rax 
0x10cc3fa30: popq %rbp 
0x10cc3fa31: retq 
0x10cc3fa32: nopw %cs:(%rax,%rax) 

我显然错过了一个简单的一步,只是不知道它是什么!

回答

0

我得到以下错误:

swift_dynamicCastClassUnconditional

斯威夫特动态转换失败

问题代码:我用CredentialsSetting视图控制器每次当连接到不同的赛格瑞

// programming mark ----- ----- ---- ----- ----- ---- ----- ----- ---- 

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 

      var detailController = segue.destinationViewController as CredentialsSetting; 
      detailController.viewControllerType = self.viewControllerType 


    }// end prepareForSegue 

解决方案:为了解决这个问题,我添加了特定的条件来传递不同的连接ns:

// programming mark ----- ----- ---- ----- ----- ---- ----- ----- ---- 

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 


     if self.viewControllerType == "donothavepassword" || self.viewControllerType == "forgotpassword" { 

      var detailController = segue.destinationViewController as CredentialsSetting; 
      detailController.viewControllerType = self.viewControllerType 


     } 


    }// end prepareForSegue