top of page

Swift 3: DelegateによるViewController間でのデータ共有

Delegateに変数を宣言

class AppDelegate: UIResponder, UIApplicationDelegate {

var message:String = ""

FirstViewController

変数宣言

let appDelegate = UIApplication.shared.delegate as! AppDelegate

値をセット

appDelegate.message = "message"

SecondViewController

変数を宣言

let appDelegate = UIApplication.shared.delegate as! AppDelegate

値をゲット

let message:String = appDelegate.message


Featured Posts
後でもう一度お試しください
記事が公開されると、ここに表示されます。
Recent Posts
Search By Tags
まだタグはありません。
Connect
  • Google+ Social Icon
  • Facebook Social Icon
  • LinkedIn Social Icon
  • Twitter Social Icon
bottom of page