LoginSignup
10
10

More than 5 years have passed since last update.

初めてのiOSアプリ(Swift)で HelloWorld!

Posted at

ログ及び画面にHelloWorldを表示した時のメモ

環境

  • XCode 8.0(インストール済み)

プロジェクトを作成する

とりあえずアプリ用のプロジェクトを作成します。

  • XCodeを開く
  • Create a new XCode project を選択
  • テンプレートではiOS、SingleViewApplicationを選択
  • LanguageでSwiftを選択。また適当にProjectNameやOrganization Identifierなどを入力
  • プロジェクトを配置する任意のフォルダを選択

動かしてみる

とりあえず動かしてみます。
画面上部の再生ボタンを押すとビルド及びシュミレーターでのアプリの実行が確認できます。

スクリーンショット 2016-09-18 17.39.11.png

ログを追加してみる

ログを追加してみます。
print関数を使います。

ViewController.swift
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        print("Hello World!")
    }

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

無事ログとしてHello World!が表示されました。

画面に文字を表示する

Swift言語によるiOSアプリ開発

先程ログを仕込んだ部分に以下を追記してラベルを追加してみます。

ViewController.swift
        let label = UILabel(frame: CGRect(x: 100, y: 100, width: 200, height: 50))
        label.text = "Hello World!"
        self.view.addSubview(label)

無事表示されましたー。

スクリーンショット 2016-09-18 17.51.32.png

10
10
0

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
10
10