Brenner
Brenner

Reputation: 655

Nil is not compatible with expected argument type UIViewAnimationOptions

I just started programming and following a tutorial online I was unable to create this animation. Can anyone tell me why it's saying:

Nil is not compatible with expected argument type UIViewAnimationOptions

and how to fix it?

view.addSubview(myFirstLabel)

UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: nil, animations: {

    self.myFirstLabel.center = CGPoint(x: 100, y:40 + 200)

}, completion: nil)

Upvotes: 46

Views: 30702

Answers (3)

AaoIi
AaoIi

Reputation: 8396

You may replace options: nil with options: [] should make the error goes way.

Upvotes: 124

Mohmmad S
Mohmmad S

Reputation: 5088

It's because UIViewAnimationOptions is an OptionSet type, not Optional type OptionSet according to apple

You use the OptionSet protocol to represent bitset types, where individual bits represent members of a set.

it's mainly used to create a combined flag from the current flags inside the set, in your case animation flags or types we can call them, this will give you the ability to combine options to make the final desired option, there are about 23 option, however in your case you can just pass an empty OptionSet as []

Upvotes: 0

Jelly
Jelly

Reputation: 4522

UIViewAnimationOptions is an enum backed by integers. You should pass 0. Here is the doc for the enum.

Upvotes: 0

Related Questions