0
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.

オプショナル使い方集[Swift]

Last updated at Posted at 2019-10-20

クラスで絞る

//一番親のViewがSCNViewだったら
let scnView = self.view as! SCNView
//そいつの背景青にする
scnView.backgroundColor = UIColor.blue

if letとか

if let HugaViewController = hogehuga as! HogeViewController {
            //hogehoge
}

!ではなく**?にしてオプショナルにしなさいよ**(nilを許容しなさいよ)ということらしい

Initializer for conditional binding must have Optional type, not 'HogeViewController'
//条件付きバインディングのイニシャライザには、「HogeViewController」ではなく「Optional」型が必要です
if let HugaViewController = hogehuga as? HogeViewController {
            //hogehoge
}

あとで追記

0
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
0
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?