-1
var Testing: CATransition!
Testing.type = kCATransitionFade
Testing.duration = 1
Testing.delegate = ColorBox

I am using Swift.

On the second line, I get the error EXC_BAD_INSTRUCTION. I have read into this error and have found that this could be because a value has returned nil. Could someone please explain to me how I can fix this block of code?

Also is this even the correct way to set up a CATransition/CAAnimation?

(ColorBox is a UIView)

chappjc
  • 29,576
  • 6
  • 70
  • 120
PugLvr28
  • 111
  • 1
  • 1
  • 6

1 Answers1

0

The problem is that you have no CATransition. You have declared a CATransition variable but you have not assigned any CATransition to it. Since you declared it as an Optional (heaven knows why), it is nil. So everything else you do is an attempt to send messages to nil, and Swift doesn't let you do that.

matt
  • 447,615
  • 74
  • 748
  • 977
  • Here is some Swift CATransition code that works: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/ca886a10d17817388f5ff26a042bfc94a37f1d1b/bk2ch04p157layerTransition/ch17p505layerTransition/ViewController.swift – matt Nov 07 '14 at 03:45