###前提・実現したいこと
Swift3.0でAppDelegateにアクセスするオブジェクトを作りたいです。
使っている教科書がswift2.0のものでして、
調べて書き換えたのですが、エラーが出てしまいます。
どうか、分かる方、よろしくお願いします。
###発生している問題・エラーメッセージ
xCode8.0にて、 ビルドは成功するがシミュレーターが真っ白で、 llbdのエラーで止まる。 let ap = UIApplication.shared.delegate as! AppDelegate ここにbreak pointがある。
###該当のソースコード
Swift3.0
1 2import UIKit 3 4class FirstViewController: UIViewController { 5 6 @IBOutlet weak var dataTextField: UITextField! 7 8 9 let ap = UIApplication.shared.delegate as! AppDelegate 10 11 12 13 override func viewWillAppear(_ animated: Bool) { 14 dataTextField.text = String(ap.cmValue) 15 } 16 17 18 @IBAction func tapInpu() { 19 20 dataTextField.resignFirstResponder() 21 if let text = dataTextField.text{ 22 23 if let cmValue = Double(text){ 24 ap.cmValue = cmValue 25 } 26 } 27 } 28 29 override func viewDidLoad() { 30 super.viewDidLoad() 31 // Do any additional setup after loading the view, typically from a nib. 32 } 33 34 override func didReceiveMemoryWarning() { 35 super.didReceiveMemoryWarning() 36 // Dispose of any resources that can be recreated. 37 } 38 39 40}
###試したこと
http://stackoverflow.com/questions/24046164/how-do-i-get-a-reference-to-the-app-delegate-in-swift
上記のページを参考に、
UIApplication.sharedApplication().delegate as! AppDelegate
を
UIApplication.shared.delegate as! AppDelegate
に書き換えました。
これによりビルドは成功するようになったのですが、
Runするとここがbreak pointになって止まってしまいます。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/09 11:51
2016/10/09 12:28