socketio / socket.io-client-swift

Other
5.22k stars 843 forks source link

May I ask a Question? #994

Closed animassu closed 6 years ago

animassu commented 6 years ago

Hi, I'm completely new to objective c and currently I'm trying out this project. I'm confused on where to include this code:

" @import SocketIO;

NSURL url = [[NSURL alloc] initWithString:@"http://localhost:8080"]; SocketManager manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @YES, @"compress": @YES}]; SocketIOClient* socket = manager.defaultSocket;

[socket on:@"connect" callback:^(NSArray data, SocketAckEmitter ack) { NSLog(@"socket connected"); }];

[socket on:@"currentAmount" callback:^(NSArray data, SocketAckEmitter ack) { double cur = [[data objectAtIndex:0] floatValue];

[[socket emitWithAck:@"canUpdate" with:@[@(cur)]] timingOutAfter:0 callback:^(NSArray* data) {
    [socket emit:@"update" with:@[@{@"amount": @(cur + 2.50)}]];
}];

[ack with:@[@"Got your currentAmount, ", @"dude"]];

}];

[socket connect]; "

Please and Thank you for helping.

nuclearace commented 6 years ago

The README code assumes you're adding stuff directly to main.swift or a main function. A real app would be structured differently. (With the main point being theSocketManager should not be released by ARC.

Also, if you're new to Objective-C, I would recommend using Swift, it's much easier to learn than ObjC.