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

Using with Swift #9

Open
cfr opened this issue Feb 3, 2015 · 3 comments
Open

Using with Swift #9

cfr opened this issue Feb 3, 2015 · 3 comments

Comments

@cfr
Copy link

cfr commented Feb 3, 2015

Here is the short sample:

https://gist.github.com/cfr/dfcb50accd64014a0019

Obviously we need some kind of wrapper to avoid casting:

    let data: @objc_block (NSDictionary, AnyObject) -> () = { (d: NSDictionary, raw: AnyObject) -> () in
        NSLog("Got data: \(d)")
    }
    p.on("data" as AnyObject!, listener: unsafeBitCast(data, AnyObject.self))
@nunofgs
Copy link
Contributor

nunofgs commented Feb 3, 2015

Wow, that's really cool. I must admit I've only played around with Swift for a bit so I don't feel comfortable porting primus to Swift yet. That said, I'd love to see someone contribute a Swift wrapper.

Anyone care to give it a shot?

@danil-z
Copy link

danil-z commented Feb 10, 2015

I wonder how to stream binary data using primus-objc in order to use Spark#pipe on server side...

@katopz
Copy link
Contributor

katopz commented May 19, 2015

Here's what I got for now

class Block<T> {
    let f : T
    init (_ f: T) { self.f = f }
    var casted: AnyObject { get { return unsafeBitCast(f, AnyObject.self) } }
}

Then

primus.on("open", listener : Block<@objc_block () -> ()> {
    let _ = primus.write(["event": "roomAdd", "room": "defaultRoom"])
}.casted)

primus.on("data", listener : Block<@objc_block (NSDictionary, AnyObject) -> ()> { (d: NSDictionary, raw: AnyObject) in
    NSLog("Got data: \(d)")
}.casted)

And not sure we could use some trick from this? https://github.com/pNre/ExSwift/blob/master/ExSwift%2FExSwift.swift#L249

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

No branches or pull requests

4 participants