LoginSignup
72
78

More than 5 years have passed since last update.

【第1回】Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Build a Basic UI 編)

Last updated at Posted at 2015-10-20

はじめに

AppleのSwiftアプリ開発チュートリアルを進めていて出てきた関数やクラスなどについて、調べたことを残していきます。
チュートリアルを進めながら、ざっくりとどういうものかを把握するためのお供になればと思います。

初学者のため、間違い等あればご指摘ください。 :bow:

第1回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Build a Basic UI 編) ←今回はここ
第2回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Connect the UI to Code 編)
第3回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Work with View Controllers 編)
第4回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Implement a Custom Control 編)
第5回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Define Your Data Model 編)

チュートリアルページ

以下のような構成でレッスンが進んでいくので、それに沿って進めていきます。

  • Building the UI
    • Build a Basic UI(今回はここ)
    • Connect the UI to Code
    • Work with View Controllers
    • Implement a Custom Control
    • Define Your Data Model
  • Working with Table Views
    • Create a Table View
    • Implement Navigation
    • Implement Edit and Delete Behavior
    • Persist Data

Build a Basic UI

今回はこのレッスンで出てきたものについて見ていきます。

■ AppDelegate.swift

アプリをつくった段階でデフォルトでつくられるファイルのひとつ。
デフォルトで記載されているAppDelegateクラスはアプリ全体のライフタイムイベントを管理するためのクラス。

■ application

アプリの初期化が終わってストーリーボードの読み込みが終わった後に呼び出される。

チュートリアルでの使用例

AppDelegate.swift
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

ドキュメント

  • 公式

application(_:didFinishLaunchingWithOptions:)

■ applicationWillResignActive

アプリケーションがフォアグラウンド状態からバックグラウンド状態に変わる直前に呼ばれる。
ざっくり言うとアプリが閉じそうな時に呼ばれる

チュートリアルでの使用例

AppDelegate.swift
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

ドキュメント

  • 公式

applicationWillResignActive(_:)

■ applicationDidEnterBackground

アプリケーションがバックグラウンド状態になったら呼ばれる。
ざっくり言うとアプリが閉じた時に呼ばれる

チュートリアルでの使用例

AppDelegate.swift
    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

ドキュメント

■ applicationWillEnterForeground

アプリケーションがバックグラウンド状態から復帰する直前に呼ばれる。
ざっくり言うとアプリが開きそうな時に呼ばれる

チュートリアルでの使用例

AppDelegate.swift
    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

ドキュメント

■ applicationDidBecomeActive

アプリケーションがフォアグラウンド(前面実行)状態になったら呼ばれる。
ざっくり言うとアプリが開いた時に呼ばれる

チュートリアルでの使用例

AppDelegate.swift
    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

ドキュメント

■ applicationWillTerminate

ざっくり言うとフリックしてアプリを終了させる際に、アプリ終了の直前に呼ばれる

※アプリが完全に終了する直前であれば、フリック終了には限らない

チュートリアルでの使用例

AppDelegate.swift
    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

ドキュメント


参考サイト

http://qiita.com/SoyaTakahashi/items/cc8f48af792c353cd9f3
http://d.hatena.ne.jp/glass-_-onion/20120405/1333611664

次のレッスン

第2回:Swiftアプリ開発チュートリアル -Food Tracker- のお供に(Connect the UI to Code 編)

最後に

このレッスンではXcodeの使い方やストーリーボードを用いてのUI作成がメインだったので、あまり多くのコードは書いていないですね。
このような形で各レッスン毎に出てきた関数等をざっくり調べていき、チュートリアルを進めながら確認できるように残そうと思います。

72
78
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
72
78