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

swift / URLエンコード

        let query = "ニュース";
        let encoded = query.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
        let url = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&hl=ja&rsz=8&q=" + encoded!;