Closed danipralea closed 9 years ago
This will work if you manually include the files
@import Foundation;
#import "SwiftIOObjc-Swift.h" // Your auto-generated Objective-C interface header
@interface Tester : NSObject
@property (readwrite, nonatomic) SocketIOClient* socket;
- (id)init;
- (void)connect;
- (void)sendMessage:(NSString*)msg;
@end
@implementation Tester : NSObject
- (id)init
{
if (self = [super init]) {
self.socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:@{@"log": @NO, @"connectParams": @{@"thing": @"value"}}];
[[self socket] onAny:^(SocketAnyEvent* event) {
// NSLog(@"Got event: %@, with items: %@", event.event, event.items);
}];
[[self socket] onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
NSLog(@"socket connected");
}];
[[self socket] onObjectiveC:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
double cur = [[data objectAtIndex:0] floatValue];
[[self socket] emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
[[self socket] emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
});
ack(@[@"Got your ack, ", @"dude"]);
NSLog(@"Sent ack");
}];
}
return self;
}
- (void)connect
{
[[self socket] connectWithTimeoutAfter: 5 withTimeoutHandler: ^{
NSLog(@"Client failed to connect");
}];
}
- (void)sendMessage:(NSString*)msg
{
for (int i = 0; i < 1004000; i++) {
[[self socket] emit:@"test" withItems:@[msg]];
}
}
@end
Yes, I tried again. Now it's working. Thank you!
Hello! Is there any way we can have a guide to building the library to an existing Objective-C project?
I have tried with both importing the files manually, and Cocoapods, and I have no success in doing so. Thanks in advance!