I have a library class wrote in swift which should be used in my existing objective-c code. I have created the bridging-header and have define @class MySwiftClass in .h and import "-Swift.h" in .m
a swift class is something similar to this
@objc class MySwiftClass: NSObject {
var firstName : String
var lastName: String
public init(firstName: String, lastName: String) throws {
guard !firstName.isEmpty && !lastName.isEmpty else { throw SOME_ERROR }
self.firstName = firstName
self.lastName = lastName
super.init()
}
func methodWithParams(city: String, suburb: String) throws -> String {
return city + suburb
}
I have faced two problems.
Don't know how to call swift
initfunction on the objective-c class. I have triedMySwiftClass *myClass = [MySwiftClass init];. Up to this, the app can compile. But don't know how to pass the parameters.I also want to access
myClass.methodWithParams(city:"My city", suburb:"My country")in objective-c class.
Appreciate the help!
@objcto the methods which should be visible from Objective-C.