Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignalR-swift and Objective-C cannot be mixed #27

Open
LayDownAll opened this issue Dec 28, 2017 · 4 comments
Open

SignalR-swift and Objective-C cannot be mixed #27

LayDownAll opened this issue Dec 28, 2017 · 4 comments

Comments

@LayDownAll
Copy link

There is no method in the bridge file generated by cocaspods,
2017-12-28 3 22 52
so the swift cannot be invoked in the OC project

@kamrankhan07
Copy link
Contributor

kamrankhan07 commented Jan 12, 2018

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.

@LayDownAll
Copy link
Author

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

@kamrankhan07
Copy link
Contributor

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.

@kamrankhan07
Copy link
Contributor

kamrankhan07 commented Jan 16, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants