ものすごく初歩的そうなことですいません。
プログラムの練習としてクッキークリッカーもどきのようなものを作っていて、ボタンを押したらカウントが増えるようにしたいのですが、文字データ(?)として扱われているようで、1+1=2のはずが、1+1=11、11+1=111というように増えていってしまいます。
なので、String->Intを参考に型を変えようとしたのですが、色々なところでエラーが出てしまい、私には無理でした...。
この方法ではなくてもいいので、解決法を教えてください。
swift
1import UIKit 2 3class ViewController2home: UIViewController { 4 5 var touchX = String(1); 6 var must1:String = "" 7 8 @IBOutlet weak var mustLabel: UILabel! 9 @IBOutlet weak var TouchButton: UIButton! 10 @IBAction func TouchAction(_ sender: AnyObject) { 11 must1 = must1 + touchX 12 mustLabel.text = String(must1) 13 let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 14 appDelegate.must = must1 15 } 16 17 18 override func viewDidLoad() { 19 super.viewDidLoad() 20 let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 21 if let must = appDelegate.must { 22 must1 = must 23 } 24 25 // Do any additional setup after loading the view. 26 } 27 28 override func didReceiveMemoryWarning() { 29 super.didReceiveMemoryWarning() 30 // Dispose of any resources that can be recreated. 31 } 32 33 34 /* 35 // MARK: - Navigation 36 37 // In a storyboard-based application, you will often want to do a little preparation before navigation 38 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 39 // Get the new view controller using segue.destinationViewController. 40 // Pass the selected object to the new view controller. 41 } 42 */ 43 44} 45
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。