I have a class like following
Class ViewControlelr: UIViewController {
func instantiateDocumentSubPartNavigationVC(documentPart: DocumentPart, documentPartsArray: [DocumentPart]) {
//definition
}
}
In other class called ViewController2, I wanna call above method. I expect to see below so I can pass parameters to the method in ViewController2
ViewController.instantiateDocumentSubPartNavigationVC(documentPart: DocumentPart, documentPartsArray: [DocumentPart])
But what I actually see is
ViewController.instantiateDocumentSubPartNavigationVC(ViewController)
How can I successfully utilize the class method in different class?
Functions can be declared to operate at one of two levels - class or instance. When you call a function, you have to match correctly.
Currently your code has ViewController.instantiateDocumentSubPartNavigationVC
, and ViewController
is a class, not an instance of a class. This does not match the function, which is declared to operate on an instance (since it doesn't have the keyword class
or static
).
So either you need to use an instance of a ViewController
(which might be viewController
with a little 'l'), or declare the function with class
. The choice depends on what you're trying to do, but it's most likely the first option.
This is why your question got marked as duplicate - because it looks like you want to call one class-level function from another class-level function, but I suspect that's not what you're after.