Code Monkey home page Code Monkey logo

Comments (12)

nuclearace avatar nuclearace commented on May 18, 2024

Thanks for the good issue report.

I don't really know Objective-C well, but from your test code it looks like you're creating a local variable named socket and working with that. Once socket goes out of scope it should be released.

Does this happen if you make the socket a member of the viewcontroller?

I usually have the socket be a member of the viewcontroller, and then do things like this in the viewDidLoad https://github.com/nuclearace/socket.io-client-swift-example/blob/master/TicTacIOiOS/ViewController.swift#L28

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

Also, I should note I have no idea if Objective-C blocks are as powerful as Swift closures.

from socket.io-client-swift.

ahallora avatar ahallora commented on May 18, 2024

Thanks for a quick reply - I will look into it and report my findings. 😄

I know less swift than objective-c so I have my work cut out for me. 😄

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

Hm, actually I'm getting this too.

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

What's weird is this seems to work in Swift.

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

Also the code it's highlighting isn't the problem.

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

Swift 1.2 seems to get the line right, but I still can't figure out why it's happening

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

What's even weirder is that it doesn't seem to happen when I do something crazy like

SocketIOClient* gSocket;

void testSocketAck()
{
    gSocket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];

    [gSocket on: @"connect" callback: ^(NSArray* data, void (^ack)(NSArray*)) {
        NSLog(@"connected");
        [gSocket emitWithAckObjc:@"ack" withItems:@[@1]](1, ^(NSArray* data) {
            NSLog(@"Got ack");
            NSLog(@"%@", data[0]);
            [gSocket emitObjc:@"test" withItems:@[]];
        });
    }];

    [gSocket connect];
}

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

Ugh, I found a really ugly workaround.

If you have a global variable that references your object, and then use that inside blocks it works.

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

@ahallora Actually I think I've found a solution

- (void) sendMessage {
    __block int i;

    [[self socket] emitWithAckObjc:@"ack" withItems:@[@1]](1, [^(NSArray* data) {
        NSLog(@"Got ack");

        [[self socket] emitObjc:@"test" withItems:@[]];
        i = 1 + 1;
    } copy]);
}

Can you confirm that sending the copy message to the block fixes it.

If that's the case, I'll update the readme

from socket.io-client-swift.

nuclearace avatar nuclearace commented on May 18, 2024

This is actually a problem with Swift-Objective-C compatibility. I worked out a small demo here

from socket.io-client-swift.

ahallora avatar ahallora commented on May 18, 2024

Awesome, it works! Thank you so much! 👍 😃

from socket.io-client-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.