LoginSignup
0
1

More than 5 years have passed since last update.

Swiftでボタンをタップする度に数字がインクリメントされてくプログラムを実装

Last updated at Posted at 2016-09-27


import UIKit



class ViewController: UIViewController {

    var tapCount:Int = 0
    //変数tapCountにInt型の0を代入

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }





    @IBAction func count(sender: AnyObject) {
        //selfで自分を呼び出して自分の中の変数tapCountを += 1でインクリメント
        self.tapCount += 1
        //printでtapCountがインクリメントされてるかデバックで確認
        print(tapCount)

    }
}

やったこと

  • ボタンを作る
  • ボタンをタップするごとに変数の中の数字をインクリメントさせる

この後実装したいこと

  • DBのRealmの練習
  • 数字がインクリメントされるごとに数字をDBに送る
  • インクリメントされた全ての数字が個別にDBに保持される
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1