Open LayDownAll opened 6 years ago
I am using it with objective-C, works fine. I think you have to create a new swift file that is visible in objective-C and use to communicate between swift and objective-C. For Example
@objc class SignalR: NSObject {
fileprivate let hubConnection = HubConnection(withUrl: "https://someurl/hub")
func addListner(hub hubName: String, target targetObj: AnyObject) {
if let proxy = self.hubConnection.createHubProxy(hubName: hubName) {
self.hubConnection.start()
proxy.invoke(method: methodName, withArgs: [args1, arg2], completionHandler: { (response, error) in
})
}
}
}
....
//Write all your methods here and just communicate
}
Let me know if you need any further help with this.
I create a swift file, write inside the communication method, but I do not know when referenced in the OC method of how to call in the file, I will not read the original swift language, swift3.0 swift development but not a long time so, many are not, this is the first time using swift and OC mixed, I watch the evening course directly import the cocapods, will generate a bridging file inside the method and object object creation data, but when I use the cocapods import SignalRSwift did not produce any method, this makes me unable to start, I don't know how to go to Diao
I think you are on the right path. I will try to create a demo project without much code to show that its working and will post here.
I think I get your issue, you can't access all of the Swift code directly in Objective-C, e.g. enums written in Swift can't be used in objective-C, unless they are of Int type. So what you will need is to create intermediate classes written in Swift that will just take some data as input and communicate with SignalR and return you back just the data. Or you can create proxy objects that are visible in Objective-C for the Swift API. I would suggest you to just use intermediate classes to fetch data and keep all your other logic in Swift. I am attaching the sample project SignalRObjectiveCIntegration.zip
There is no method in the bridge file generated by cocaspods,
so the swift cannot be invoked in the OC project