[macOS] Hello World的なもののiOS版だ。
まず、プロジェクトを作るところから。
Xcodeを起動してFile -> New -> ProjectでiOSのSingle Viewを選ぶ。
次の画面で
Product Name(ここではHelloWorldと入力)、Organization Nameに名前、Organization Identifierにドメイン名を逆順に並べたやつを入力する。それ以外は、↑画像のように設定する。Bundle Identifierは、Organization IdentifierとProduct Nameから作られて、アプリを識別するためのIDとなる。
Nextボタンを押して、次の画面でプロジェクトの保存先を指定する。
実機で動かすにはTeamを設定する必要がある。
あとは、[macOS] Hello World的なものと手順はほぼ一緒。クラス名やら使い方がクラスの使い方がちょっと違う。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
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 buttonClick(_ sender: Any) {
label.text = "こんにちは!"
}
}
コメント