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

How to integrate this library with swift using cocoapods #5

Open
linkrjr opened this issue Sep 14, 2015 · 3 comments
Open

How to integrate this library with swift using cocoapods #5

linkrjr opened this issue Sep 14, 2015 · 3 comments

Comments

@linkrjr
Copy link

linkrjr commented Sep 14, 2015

I have been trying all the documented ways to import objective-c code into swift and I keep getting errors.

Have you guys managed to do this?

@gianlucabertani
Copy link
Member

Sorry to hear you are experiencing problems.

We managed to do this and it was actually pretty straight. Just follow these steps:

  • Create your pod file and add the following line:
pod 'LSThreadPoolLib'
  • Run pod install to update your project;
  • Create a .h file, call it something like Bridge.h and add the following line:
#import <LSThreadPoolLib/LSThreadPoolLib.h>
  • Set the name of the bridging header in your project settings (pay attention to prefixing the correct folder name):

    Objective-C Bridging Header MyProject/Bridge.h

  • Your project should now be ready to use our library. As an example, the following view controller provides some sample calls to a thread pool and the URL dispatcher:

import UIKit

class ViewController: UIViewController, LSURLDispatchDelegate {
    var _pool : LSThreadPool = LSThreadPool(name: "TestPool", size: 1)

    override func viewDidLoad() {
        super.viewDidLoad()

        _pool.scheduleInvocationForBlock { () -> Void in
            let url = NSURL(string: "http://push.lightstreamer.com/lightstreamer/create_session.txt?LS_user=&LS_adapter_set=DEMO&LS_ios_version=1.0")
            let req = NSURLRequest(URL: url!)
            LSURLDispatcher.sharedDispatcher().dispatchShortRequest(req, delegate: self)

            dispatch_async(dispatch_get_main_queue(), {
                let alert = UIAlertView(
                    title: "Alert",
                    message: "Opening session now...",
                    delegate: nil,
                    cancelButtonTitle: "Ok")

                alert.show()
            })
        }
    }

    func dispatchOperation(operation: LSURLDispatchOperation, didReceiveResponse: NSURLResponse) {
        NSLog("Response: \(didReceiveResponse)")
    }

    func dispatchOperation(operation: LSURLDispatchOperation, didReceiveData: NSData) {
        NSLog("Data: \(didReceiveData)")
    }

    func dispatchOperation(operation: LSURLDispatchOperation, didFailWithError: NSError) {
        NSLog("Error: \(didFailWithError)")
    }

    func dispatchOperationDidFinish(operation: LSURLDispatchOperation) {
        NSLog("Finish")
    }
}

Hope this helps.

@kos9kus
Copy link

kos9kus commented Apr 19, 2016

Could we anticipate you'd rewrite an implementation in Swift entirely?
Or It doesn't make sense ?

@gianlucabertani
Copy link
Member

At the moment we are not investing time on this library, since it has reached its objectives and there are no open issues. But should we decide to rewrite our iOS/OS X/tvOS clients to Swift, it would be surely part of the rewrite.

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

3 participants