1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

xcodeでViewController間で値のやり取りをする方法

1
Posted at

appDelegate.swiftに変数を作成し、アプリ全体で使えるグローバル変数にする。

AppDelegate.swift
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var count:Int = 0
}
ViewController.swift

	//delegateオブジェクトを作る
	let delegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

	delegate.count = 10 //このようにして、データを代入したり、やり取りを行ったりする
	
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?