I'm trying to call an instance method from a class method in Swift, but I keep getting the error "Missing argument for parameter #1 in call" on the "someMethod()" call.
Do you know why?
Here's the code:
class ViewController: UIViewController {
class func updateData() {
someMethod()
}
func someMethod() {
NSLog("someMethod")
}
}
updateData
is declared as a class method (i.e. static), and it's executed in the context of the class type and not a class instance. On the other hand,someMethod
is an instance method.You cannot execute an instance method from a static method, unless you provide an instance.
Without knowing the logic of your app, it's hard to figure out how the problem should be solved. Some possible solutions:
make
uploadData
an instance method, by removingclass
from its signature:make
someMethod
a static method: