0

I just updated Xcode to 7.0.1 and therefore also Swift from Swift 1 to Swift 2.

I got a lot of errors when the update was done and this is one of the problems I can not fix. It would be really nice if you could fix this for me.

The error message says:

Nil is not compatible with expected type UIViewAnimationOption'

UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: nil, animations: ({

}), completion: nil)
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    possible duplicate of [Whats the Swift 2.0 animateWithDuration syntax?](http://stackoverflow.com/questions/30991822/whats-the-swift-2-0-animatewithduration-syntax) – Dharmesh Kheni Sep 29 '15 at 17:19

3 Answers3

1

Use UIViewAnimationOptions property object for options:

UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

}, completion: nil)
Nishant
  • 12,529
  • 9
  • 59
  • 94
0

You can use like this:

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

        }) { (finished: Bool) -> Void in

    }

or

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.Autoreverse], animations: { () -> Void in

        }, completion: nil)
Kingiol
  • 1,145
  • 9
  • 9
0

In Swift 2 UIViewAnimationOption is declared as non optional. Therefore it cannot be nil. The equivalent to no options is the generic initializer

... options: UIViewAnimationOption() ...

or a pair of empty brackets

... options: [] ...
vadian
  • 274,689
  • 30
  • 353
  • 361