お世話になります。
swiftにて以下のようにdelegateを実装しようとしているのですが、なぜか"unexpectedly found nil while unwrapping an Optional value"というエラーになってしまう理由をおしえて頂きたいです。
コードは以下になります。
swift
1 2protocol TestDelegate { 3 func sayHello() 4} 5 6class A { 7 8... 9 10 var delegate: TestDelegate! // nil 11 12... 13 14 func onClickButton() { 15 self.delegate.sayHello() 16 // unexpectedly found nil while unwrapping an Optional value 17 } 18 19} 20 21class B: TestDelegate { 22 23... 24 25 let a = A() 26 a.delegate = self 27 28... 29 30 func sayHello() { 31 println("hello") 32 } 33 34}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/08/21 12:09 編集
退会済みユーザー
2015/08/21 12:09 編集
2015/08/21 17:50
退会済みユーザー
2015/08/24 21:57
2015/08/25 03:41