3254523
3254523

Reputation: 3026

Extra arguement in method call

I'm looking to call a method from my ViewController class that is declared in another class.

in my Animator class:

class Animator {

    func animate(view:View!, scrollView:UIScrollView!) {
    //animation code
    }
}

but when i call the method in my View Controller class

Animator.animate(viewA, scrollView:scrollView)

i get a "Extra Argument 'scrollView' in call error

It's so simple and i'm so confused on why this error is showing for me.

Upvotes: 0

Views: 121

Answers (2)

Snowman
Snowman

Reputation: 32091

You're calling animate as if it were a class method. If you want it to be a class method, you need to do:

class func animate(view:View!, scrollView:UIScrollView!)

If you want it to be an instance method, first create an instance of Animator, then call animate on the instance:

a = Animator()
a.animate(view, scrollView:scrollView)

Upvotes: 3

Alex Wayne
Alex Wayne

Reputation: 187262

Should that be UIView instead of View?

func animate(view:UIView!, scrollView:UIScrollView!) { ... }

And you are calling this on a class, so it needs to be a class method.

class func animate(view:UIView!, scrollView:UIScrollView!) { ... }

And I also believe that call needs to have a named argument:

Animator.animate(view: viewA, scrollView:scrollView)

Error messages in Swift can be misleading :(

Upvotes: 0

Related Questions