Help us understand the problem. What is going on with this article?

SwiftでUIViewController

More than 5 years have passed since last update.

Swiftを早速いじってみました。感想としてはすっごくRubyMotionみたいだな...という感じ。リファレンスひきながらでも言語仕様はどこかでみたことある系なので数日あれば慣れるような気がします。

ObjectiveCは基本なところがめんどくさいんだよね...と思ってRubyMotionを好んで使っている自分にはなかなか魅力的です。

ViewController.swift 

StoryboardにUILableとUIButtonを貼り付けて、アシスタントエディタをつなげたら下記のようなコードになりました。

接続に@IBOutlet、アクションには@IBAction func....と書くのですね。sender:id が sender : AnyObjectになっているくらいですかね。

スクリーンショット_2014-10-23_18_37_49.jpg

UIButtonを押すたびに1.2.3.4とカウントアップしていくだけのコードです。

ViewController.swift
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var label: UILabel!

    var countNum = 1

    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 actionButton(sender: AnyObject) {
        label.text = String(countNum)
        countNum++
    }

}

という事でここまでは簡単です。

追記

意外にストックされているので、最新のXcode6.1のコードに書き換えました(2014/10/23)

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away