Latest 0.2
Homepage https://github.com/YaxinCheng/SocketKit
License MIT
Platforms ios 10.0
Authors

A wrapped Swift toolkit for socket connection

Requirements:

  • Xcode 8.0+
  • iOS 10.0+
  • Swift 3.0+

Installation:

SocketKit can be installed through Cocoapods or manual import.

Cocoapods:

$ gem install cocoapods

After installation of cocoapods, create a file named Podfile at the root directory of the project:

For swift3:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'SocketKit'
end

Then, run the following command:

$ pod install

User Manual:

Kit imports

import SocketKit

Socket.swift

The only class will be used in the kit. All the requests go from this kit.

Constructor

public init(address: String, port: Int) throws { ... }

SocketError.connectionFailed may be thrown from the constructor when connection failed

Read from socket

public func read(complete: @escaping (String?) -> Void) throws { ... }

This function accepts a call back closure, which will be called when value is read from socket server side
The closure accepts an optional string, and may throw out a SocketError.notConnected if the socket lost connection

Write to socket

public func write(value: String) throws { ... }

This function accepts an UTF-8 string value, and encode the string to binary data, then write to the socket server.
SocketError.notConnected may be thrown if the socket connection is lost
SocketError.notWritable may be thrown if the socket is not allowed to write values
SocketError.dataEncodingFailed may be thrown if the string value cannot be encoded

Connection status

public var isConnected: Bool

This attribute returns true if the socket is connected, otherwise false

License

WeatherKit is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "SocketKit",
    "version": "0.2",
    "summary": "A wrapped Swift toolkit for socket connection",
    "description": "A wrapped Swift toolkit for socket connection with simplified IO functions.nEasy to use and create.",
    "homepage": "https://github.com/YaxinCheng/SocketKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Yaxin Cheng": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/YaxinCheng/SocketKit.git",
        "tag": "0.2"
    },
    "source_files": [
        "SocketKit",
        "SocketKit/**/*.{h,swift}"
    ]
}

Pin It on Pinterest

Share This