Skip to content

Commit d0a57ca

Browse files
committed
tweak to objective-c api
1 parent 9355fc5 commit d0a57ca

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ socket.connect()
2828
```objective-c
2929
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
3030

31-
[socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
31+
[socket onEvent:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
3232
NSLog(@"socket connected");
3333
}];
3434

35-
[socket onObjectiveC:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
35+
[socket onEvent:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
3636
double cur = [[data objectAtIndex:0] floatValue];
3737

3838
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
@@ -130,16 +130,16 @@ Options
130130

131131
Methods
132132
-------
133-
1. `on(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
134-
2. `onObjectiveC(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
135-
3. `onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
136-
4. `emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
137-
5. `emit(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
138-
6. `emitWithAck(event:String, _ items:AnyObject...) -> (timeoutAfter:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function.
139-
7. `emitWithAck(event:String, withItems items:[AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function.
133+
1. `on(event: String, callback: ((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
134+
2. `on(event event: String, callback:((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
135+
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
136+
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
137+
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
138+
6. `emitWithAck(event: String, _ items: AnyObject...) -> (timeoutAfter:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function.
139+
7. `emitWithAck(event: String, withItems items: [AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function.
140140
8. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
141-
9. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
142-
10. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task.
141+
9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
142+
10. `close(fast fast: Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task.
143143
11. `reconnect()` - Causes the client to reconnect to the server.
144144
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
145145
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /

SocketIOClientSwift/SocketIOClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
417417
/**
418418
Adds a handler for an event.
419419
*/
420-
public func onObjectiveC(event: String, callback: NormalCallbackObjectiveC) {
420+
public func on(event event: String, callback: NormalCallbackObjectiveC) {
421421
Logger.log("Adding handler for event: %@", type: logType, args: event)
422422

423423
let handler = SocketEventHandler(event: event, callback: callback)

SocketIOClientSwift/SocketTypes.swift

-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ public typealias AckEmitterObjectiveC = (NSArray) -> Void
3030
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
3131
public typealias NormalCallbackObjectiveC = (NSArray?, AckEmitterObjectiveC?) -> Void
3232
public typealias OnAckCallback = (timeoutAfter:UInt64, callback:AckCallback) -> Void
33-

0 commit comments

Comments
 (0)