swift / appdeligateでページ越しで共通変数を使う
AppDelegate.swiftとは?
アプリをつくった段階でデフォルトでつくられるファイルのひとつ。
アプリ全体のライフタイムイベントを管理するためのクラス。
http://qiita.com/SoyaTakahashi/items/cc8f48af792c353cd9f3
共通関数やら変数をページ越しで管理するときとかに使うとよさげ
例
appdeligate.swift
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var stampArray:[Stamp] = []; var isNewStampAdded = false
viewController.swift
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate //配列stampArrayにstampを追加 appDelegate.stampArray.append(stamp) //新規スタンプ追加フラグをtrueに設定 appDelegate.isNewStampAdded = true