From 9a2b59ad78541e32d2de67b6b171c4a9b7ac2122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Fossli?= Date: Tue, 4 Apr 2017 11:03:42 +0200 Subject: [PATCH] Update README.md --- README.md | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a891b13..f366683 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ [![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=master)](https://travis-ci.org/socketio/socket.io-client-swift) -#Socket.IO-Client-Swift +# Socket.IO-Client-Swift Socket.IO-client for iOS/OS X. -##Example +## Example ```swift import SocketIO @@ -26,7 +26,7 @@ socket.on("currentAmount") {data, ack in socket.connect() ``` -##Objective-C Example +## Objective-C Example ```objective-c @import SocketIO; NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"]; @@ -50,14 +50,14 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ ``` -##Features +## Features - Supports socket.io 1.0+ - Supports binary - Supports Polling and WebSockets - Supports TLS/SSL - Can be used from Objective-C -##Installation +## Installation Requires Swift 3/Xcode 8.x If you need swift 2.3 use the swift2.3 tag (Pre-Swift 3 support is no longer maintained) @@ -70,13 +70,11 @@ If you need Swift 1.2 use v2.4.5 (Pre-Swift 2 support is no longer maintained) If you need Swift 1.1 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained) -Manually (iOS 7+) ------------------ +### Manually (iOS 7+) 1. Copy the Source folder into your Xcode project. (Make sure you add the files to your target(s)) 2. If you plan on using this from Objective-C, read [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) on exposing Swift code to Objective-C. -Swift Package Manager ---------------------- +### Swift Package Manager Add the project as a dependency to your Package.swift: ```swift import PackageDescription @@ -91,8 +89,7 @@ let package = Package( Then import `import SocketIO`. -Carthage ------------------ +### Carthage Add this line to your `Cartfile`: ``` github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version @@ -100,8 +97,7 @@ github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version Run `carthage update --platform ios,macosx`. -CocoaPods 1.0.0 or later ------------------- +### CocoaPods 1.0.0 or later Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: ```ruby @@ -131,8 +127,7 @@ Objective-C: @import SocketIO; ``` -CocoaSeeds ------------------ +### CocoaSeeds Add this line to your `Seedfile`: @@ -143,15 +138,14 @@ github "socketio/socket.io-client-swift", "v8.3.3", :files => "Source/*.swift" # Run `seed install`. -##API -Constructors ------------ +## API + +### Constructors `init(var socketURL: NSURL, config: SocketIOClientConfiguration = [])` - Creates a new SocketIOClient. If your socket.io server is secure, you need to specify `https` in your socketURL. `convenience init(socketURL: NSURL, options: NSDictionary?)` - Same as above, but meant for Objective-C. See Options on how convert between SocketIOClientOptions and dictionary keys. -Options -------- +### Options All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase. ```swift @@ -176,8 +170,7 @@ case security(SSLSecurity) // Allows you to set which certs are valid. Useful fo case selfSigned(Bool) // Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs. case voipEnabled(Bool) // Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false ``` -Methods -------- +### Methods 1. `on(_ event: String, callback: NormalCallback) -> NSUUID` - 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. Returns a unique id for the handler. 2. `once(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler that will only be executed once. Returns a unique id for the handler. 3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event. @@ -195,18 +188,17 @@ Methods 15. `off(id id: NSUUID)` - Removes the event that corresponds to id. 16. `removeAllHandlers()` - Removes all handlers. -Client Events ------- +### Client Events 1. `connect` - Emitted when on a successful connection. 2. `disconnect` - Emitted when the connection is closed. 3. `error` - Emitted on an error. 4. `reconnect` - Emitted when the connection is starting to reconnect. 5. `reconnectAttempt` - Emitted when attempting to reconnect. -##Detailed Example +## Detailed Example A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example) An example using the Swift Package Manager can be found [here](https://github.com/nuclearace/socket.io-client-swift-spm-example) -##License +## License MIT