I have a class named Location
that has several methods in it that do not have any parameters.
However, when I try to create a variable with the result of th
Because you're trying to call it as a class function. You should be creating an instance of Location
and calling the function on that. Note also that it returns String
Where your code is telling the compiler you're expecting it to return a Location
.
These methods are not class methods, they are instance methods. You must call them on an instance of the Location
class, not on the class itself. Evidently, Swift can call instance methods similarly to Python: the method is a function owned by the class, and its argument is an instance of the class. But you should not call instance methods this way.
The best way to solve this problem is to construct a Location
object and then call the method on it:
let city: Location = Location().getCity()