Binh Binh - 4 months ago 18
Swift Question

Error accessing function of class while converting Obj C project to Swift

I added my swift class to the target while removing my header file of the same objective C class from the target but this error shows when I try and build my project. I can't attach an image right now but the error states: "Use of instance member 'url' on type 'ServerURLFactory'; did you mean to use a value of type 'ServerURLFactory' instead?"

let accessURL: NSURL = NSURL(string: "\(ServerURLFactory.url())/CygnetInstanceXMLServlet?cygnetId=\(idNumber)")!

print(accessURL)


Has anyone ran into a similar problem and how to fix this confusing bug? Its as if the program is still trying to call the Obj C function instead of explicitly calling the one in the Swift file.

Answer

You're calling .url() on ServerURLFactory itself as a type:

ServerURLFactory.url()

I guess you should instantiate the class first. Probably something like this, but it depends on how the class is implemented:

let factory = ServerURLFactory()

Then:

factory.url()
Comments