Add SocketIOClientConfiguration
This commit is contained in:
		
							parent
							
								
									437c983533
								
							
						
					
					
						commit
						e2bf84f576
					
				@ -5,7 +5,7 @@ Socket.IO-client for iOS/OS X.
 | 
			
		||||
 | 
			
		||||
##Example
 | 
			
		||||
```swift
 | 
			
		||||
let socket = SocketIOClient(socketURL: NSURL(string: "http://localhost:8080")!, options: [.Log(true), .ForcePolling(true)])
 | 
			
		||||
let socket = SocketIOClient(socketURL: NSURL(string: "http://localhost:8080")!, config: [.Log(true), .ForcePolling(true)])
 | 
			
		||||
 | 
			
		||||
socket.on("connect") {data, ack in
 | 
			
		||||
    print("socket connected")
 | 
			
		||||
@ -27,7 +27,7 @@ socket.connect()
 | 
			
		||||
##Objective-C Example
 | 
			
		||||
```objective-c
 | 
			
		||||
NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"];
 | 
			
		||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url options:@{@"log": @YES, @"forcePolling": @YES}];
 | 
			
		||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @YES, @"forcePolling": @YES}];
 | 
			
		||||
 | 
			
		||||
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
 | 
			
		||||
    NSLog(@"socket connected");
 | 
			
		||||
@ -139,7 +139,7 @@ Run `seed install`.
 | 
			
		||||
##API
 | 
			
		||||
Constructors
 | 
			
		||||
-----------
 | 
			
		||||
`init(var socketURL: NSURL, options: Set<SocketIOClientOption> = [])` - Creates a new SocketIOClient. options is a Set of SocketIOClientOption. If your socket.io server is secure, you need to specify `https` in your socketURL.
 | 
			
		||||
`init(var socketURL: NSURL, config: SocketIOClientConfiguration = [])` - Creates a new SocketIOClient. options is a Set of SocketIOClientOption. 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.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -115,6 +115,10 @@
 | 
			
		||||
		7472C65D1BCAB53E003CA70D /* SocketNamespacePacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */; };
 | 
			
		||||
		7472C65F1BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; };
 | 
			
		||||
		7472C6601BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; };
 | 
			
		||||
		747BC5991D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC5981D5F943500CA5FA4 /* SocketIOClientConfiguration.swift */; };
 | 
			
		||||
		747BC59A1D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC5981D5F943500CA5FA4 /* SocketIOClientConfiguration.swift */; };
 | 
			
		||||
		747BC59B1D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC5981D5F943500CA5FA4 /* SocketIOClientConfiguration.swift */; };
 | 
			
		||||
		747BC59F1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */; };
 | 
			
		||||
		749642B51D3FCE5500DD32D1 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749642B31D3FCE5500DD32D1 /* SSLSecurity.swift */; };
 | 
			
		||||
		749642B61D3FCE5500DD32D1 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749642B31D3FCE5500DD32D1 /* SSLSecurity.swift */; };
 | 
			
		||||
		749642B71D3FCE5500DD32D1 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749642B31D3FCE5500DD32D1 /* SSLSecurity.swift */; };
 | 
			
		||||
@ -192,6 +196,8 @@
 | 
			
		||||
		74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketParserTest.swift; sourceTree = "<group>"; };
 | 
			
		||||
		7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespacePacketTest.swift; sourceTree = "<group>"; };
 | 
			
		||||
		7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketSideEffectTest.swift; sourceTree = "<group>"; };
 | 
			
		||||
		747BC5981D5F943500CA5FA4 /* SocketIOClientConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientConfiguration.swift; path = Source/SocketIOClientConfiguration.swift; sourceTree = "<group>"; };
 | 
			
		||||
		747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = "<group>"; };
 | 
			
		||||
		749642B31D3FCE5500DD32D1 /* SSLSecurity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SSLSecurity.swift; path = Source/SSLSecurity.swift; sourceTree = "<group>"; };
 | 
			
		||||
		749642B41D3FCE5500DD32D1 /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = Source/WebSocket.swift; sourceTree = "<group>"; };
 | 
			
		||||
		74ABF7761C3991C10078C657 /* SocketIOClientSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientSpec.swift; path = Source/SocketIOClientSpec.swift; sourceTree = "<group>"; };
 | 
			
		||||
@ -314,6 +320,7 @@
 | 
			
		||||
				74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */,
 | 
			
		||||
				741F39ED1BD025D80026C9CC /* SocketEngineTest.swift */,
 | 
			
		||||
				7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */,
 | 
			
		||||
				747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */,
 | 
			
		||||
				742D150B1CA5794B00BD987D /* SocketObjectiveCTest.m */,
 | 
			
		||||
				74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */,
 | 
			
		||||
				7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */,
 | 
			
		||||
@ -346,6 +353,7 @@
 | 
			
		||||
				74171E571C10CD240062D398 /* SocketEventHandler.swift */,
 | 
			
		||||
				CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */,
 | 
			
		||||
				74171E591C10CD240062D398 /* SocketIOClient.swift */,
 | 
			
		||||
				747BC5981D5F943500CA5FA4 /* SocketIOClientConfiguration.swift */,
 | 
			
		||||
				74171E5A1C10CD240062D398 /* SocketIOClientOption.swift */,
 | 
			
		||||
				74ABF7761C3991C10078C657 /* SocketIOClientSpec.swift */,
 | 
			
		||||
				74171E5B1C10CD240062D398 /* SocketIOClientStatus.swift */,
 | 
			
		||||
@ -622,6 +630,7 @@
 | 
			
		||||
				74171EB71C10CD240062D398 /* SocketParsable.swift in Sources */,
 | 
			
		||||
				74171E811C10CD240062D398 /* SocketEnginePacketType.swift in Sources */,
 | 
			
		||||
				74171E6F1C10CD240062D398 /* SocketAnyEvent.swift in Sources */,
 | 
			
		||||
				747BC5991D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */,
 | 
			
		||||
				74171E9F1C10CD240062D398 /* SocketIOClientOption.swift in Sources */,
 | 
			
		||||
				74BC45AB1D0C6675008CC431 /* SocketClientManager.swift in Sources */,
 | 
			
		||||
			);
 | 
			
		||||
@ -679,6 +688,7 @@
 | 
			
		||||
				74171EB91C10CD240062D398 /* SocketParsable.swift in Sources */,
 | 
			
		||||
				74171E831C10CD240062D398 /* SocketEnginePacketType.swift in Sources */,
 | 
			
		||||
				74171E711C10CD240062D398 /* SocketAnyEvent.swift in Sources */,
 | 
			
		||||
				747BC59A1D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */,
 | 
			
		||||
				74171EA11C10CD240062D398 /* SocketIOClientOption.swift in Sources */,
 | 
			
		||||
				74BC45AC1D0C6675008CC431 /* SocketClientManager.swift in Sources */,
 | 
			
		||||
			);
 | 
			
		||||
@ -691,6 +701,7 @@
 | 
			
		||||
				742D150C1CA5794B00BD987D /* SocketObjectiveCTest.m in Sources */,
 | 
			
		||||
				74321DCB1C2D939A00CF6F43 /* SocketAckManagerTest.swift in Sources */,
 | 
			
		||||
				74321DCC1C2D939A00CF6F43 /* SocketParserTest.swift in Sources */,
 | 
			
		||||
				747BC59F1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift in Sources */,
 | 
			
		||||
				7472C6601BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */,
 | 
			
		||||
				74171EA81C10CD240062D398 /* SocketIOClientStatus.swift in Sources */,
 | 
			
		||||
				741F39EF1BD025D80026C9CC /* SocketEngineTest.swift in Sources */,
 | 
			
		||||
@ -724,6 +735,7 @@
 | 
			
		||||
				74171EBB1C10CD240062D398 /* SocketParsable.swift in Sources */,
 | 
			
		||||
				74171E851C10CD240062D398 /* SocketEnginePacketType.swift in Sources */,
 | 
			
		||||
				74171E731C10CD240062D398 /* SocketAnyEvent.swift in Sources */,
 | 
			
		||||
				747BC59B1D5F943500CA5FA4 /* SocketIOClientConfiguration.swift in Sources */,
 | 
			
		||||
				74171EA31C10CD240062D398 /* SocketIOClientOption.swift in Sources */,
 | 
			
		||||
				74BC45AD1D0C6675008CC431 /* SocketClientManager.swift in Sources */,
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								SocketIO-MacTests/SocketIOClientConfigurationTest.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								SocketIO-MacTests/SocketIOClientConfigurationTest.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
//
 | 
			
		||||
//  TestSocketIOClientConfiguration.swift
 | 
			
		||||
//  Socket.IO-Client-Swift
 | 
			
		||||
//
 | 
			
		||||
//  Created by Erik Little on 8/13/16.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
import XCTest
 | 
			
		||||
import SocketIOClientSwift
 | 
			
		||||
 | 
			
		||||
class TestSocketIOClientConfiguration: XCTestCase {
 | 
			
		||||
    var config = [] as SocketIOClientConfiguration
 | 
			
		||||
 | 
			
		||||
    override func setUp() {
 | 
			
		||||
        super.setUp()
 | 
			
		||||
        
 | 
			
		||||
        config = [.Log(false), .ForceNew(true)] as SocketIOClientConfiguration
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func testReplaceSameOption() {
 | 
			
		||||
        config.insert(.Log(true))
 | 
			
		||||
        
 | 
			
		||||
        XCTAssertEqual(config.count, 2)
 | 
			
		||||
        
 | 
			
		||||
        switch config[0] {
 | 
			
		||||
        case let .Log(log):
 | 
			
		||||
            XCTAssertTrue(log)
 | 
			
		||||
        default:
 | 
			
		||||
            XCTFail()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    func testIgnoreIfExisting() {
 | 
			
		||||
        config.insert(.ForceNew(false), replacing: false)
 | 
			
		||||
        
 | 
			
		||||
        XCTAssertEqual(config.count, 2)
 | 
			
		||||
        
 | 
			
		||||
        switch config[1] {
 | 
			
		||||
        case let .ForceNew(new):
 | 
			
		||||
            XCTAssertTrue(new)
 | 
			
		||||
        default:
 | 
			
		||||
            XCTFail()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -21,7 +21,7 @@
 | 
			
		||||
- (void)setUp {
 | 
			
		||||
    [super setUp];
 | 
			
		||||
    NSURL* url = [[NSURL alloc] initWithString:@"http://localhost"];
 | 
			
		||||
    self.socket = [[SocketIOClient alloc] initWithSocketURL:url options:nil];
 | 
			
		||||
    self.socket = [[SocketIOClient alloc] initWithSocketURL:url config:nil];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)testOnSyntax {
 | 
			
		||||
 | 
			
		||||
@ -80,7 +80,7 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
 | 
			
		||||
    private var selfSigned = false
 | 
			
		||||
    private var voipEnabled = false
 | 
			
		||||
 | 
			
		||||
    public init(client: SocketEngineClient, url: NSURL, options: Set<SocketIOClientOption>) {
 | 
			
		||||
    public init(client: SocketEngineClient, url: NSURL, options: SocketIOClientConfiguration) {
 | 
			
		||||
        self.client = client
 | 
			
		||||
        self.url = url
 | 
			
		||||
        
 | 
			
		||||
@ -127,7 +127,7 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public convenience init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) {
 | 
			
		||||
        self.init(client: client, url: url, options: options?.toSocketOptionsSet() ?? [])
 | 
			
		||||
        self.init(client: client, url: url, options: options?.toSocketConfiguration() ?? [])
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    deinit {
 | 
			
		||||
 | 
			
		||||
@ -89,12 +89,12 @@ extension NSDictionary {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    func toSocketOptionsSet() -> Set<SocketIOClientOption> {
 | 
			
		||||
        var options = Set<SocketIOClientOption>()
 | 
			
		||||
    func toSocketConfiguration() -> SocketIOClientConfiguration {
 | 
			
		||||
        var options = [] as SocketIOClientConfiguration
 | 
			
		||||
        
 | 
			
		||||
        for (rawKey, value) in self {
 | 
			
		||||
            if let key = rawKey as? String, opt = NSDictionary.keyValueToSocketIOClientOption(key, value: value) {
 | 
			
		||||
                options.insertIgnore(opt)
 | 
			
		||||
                options.insert(opt)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
@ -102,14 +102,6 @@ extension NSDictionary {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Set where Element : ClientOption {
 | 
			
		||||
    mutating func insertIgnore(element: Element) {
 | 
			
		||||
        if !contains(element) {
 | 
			
		||||
            insert(element)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension String {
 | 
			
		||||
    func toArray() throws -> [AnyObject] {
 | 
			
		||||
        guard let stringData = dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) else { return [] }
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
 | 
			
		||||
 | 
			
		||||
    public var forceNew = false
 | 
			
		||||
    public var nsp = "/"
 | 
			
		||||
    public var options: Set<SocketIOClientOption>
 | 
			
		||||
    public var config: SocketIOClientConfiguration
 | 
			
		||||
    public var reconnects = true
 | 
			
		||||
    public var reconnectWait = 10
 | 
			
		||||
    public var sid: String? {
 | 
			
		||||
@ -67,15 +67,15 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
 | 
			
		||||
    var waitingPackets = [SocketPacket]()
 | 
			
		||||
    
 | 
			
		||||
    /// Type safe way to create a new SocketIOClient. opts can be omitted
 | 
			
		||||
    public init(socketURL: NSURL, options: Set<SocketIOClientOption> = []) {
 | 
			
		||||
        self.options = options
 | 
			
		||||
    public init(socketURL: NSURL, config: SocketIOClientConfiguration = []) {
 | 
			
		||||
        self.config = config
 | 
			
		||||
        self.socketURL = socketURL
 | 
			
		||||
        
 | 
			
		||||
        if socketURL.absoluteString.hasPrefix("https://") {
 | 
			
		||||
            self.options.insertIgnore(.Secure(true))
 | 
			
		||||
            self.config.insert(.Secure(true))
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        for option in options {
 | 
			
		||||
        for option in config {
 | 
			
		||||
            switch option {
 | 
			
		||||
            case let .Reconnects(reconnects):
 | 
			
		||||
                self.reconnects = reconnects
 | 
			
		||||
@ -98,15 +98,15 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        self.options.insertIgnore(.Path("/socket.io/"))
 | 
			
		||||
        self.config.insert(.Path("/socket.io/"), replacing: false)
 | 
			
		||||
        
 | 
			
		||||
        super.init()
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /// Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity.
 | 
			
		||||
    /// If using Swift it's recommended to use `init(socketURL: NSURL, options: Set<SocketIOClientOption>)`
 | 
			
		||||
    public convenience init(socketURL: NSURL, options: NSDictionary?) {
 | 
			
		||||
        self.init(socketURL: socketURL, options: options?.toSocketOptionsSet() ?? [])
 | 
			
		||||
    public convenience init(socketURL: NSURL, config: NSDictionary?) {
 | 
			
		||||
        self.init(socketURL: socketURL, config: config?.toSocketConfiguration() ?? [])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    deinit {
 | 
			
		||||
@ -117,7 +117,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
 | 
			
		||||
    private func addEngine() -> SocketEngineSpec {
 | 
			
		||||
        DefaultSocketLogger.Logger.log("Adding engine", type: logType)
 | 
			
		||||
 | 
			
		||||
        engine = SocketEngine(client: self, url: socketURL, options: options)
 | 
			
		||||
        engine = SocketEngine(client: self, url: socketURL, options: config)
 | 
			
		||||
 | 
			
		||||
        return engine!
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										107
									
								
								Source/SocketIOClientConfiguration.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								Source/SocketIOClientConfiguration.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,107 @@
 | 
			
		||||
//
 | 
			
		||||
//  SocketIOClientConfiguration.swift
 | 
			
		||||
//  Socket.IO-Client-Swift
 | 
			
		||||
//
 | 
			
		||||
//  Created by Erik Little on 8/13/16.
 | 
			
		||||
//
 | 
			
		||||
//  Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
//  of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
//  in the Software without restriction, including without limitation the rights
 | 
			
		||||
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
//  copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
//  furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
//  The above copyright notice and this permission notice shall be included in
 | 
			
		||||
//  all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
//  THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
public struct SocketIOClientConfiguration : ArrayLiteralConvertible, CollectionType, MutableCollectionType {
 | 
			
		||||
    public typealias Element = SocketIOClientOption
 | 
			
		||||
    public typealias Index = Array<SocketIOClientOption>.Index
 | 
			
		||||
    public typealias Generator = Array<SocketIOClientOption>.Generator
 | 
			
		||||
    public typealias SubSequence =  Array<SocketIOClientOption>.SubSequence
 | 
			
		||||
    
 | 
			
		||||
    private var backingArray = [SocketIOClientOption]()
 | 
			
		||||
    
 | 
			
		||||
    public var startIndex: Index {
 | 
			
		||||
        return backingArray.startIndex
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public var endIndex: Index {
 | 
			
		||||
        return backingArray.endIndex
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public var isEmpty: Bool {
 | 
			
		||||
        return backingArray.isEmpty
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public var count: Index.Distance {
 | 
			
		||||
        return backingArray.count
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public var first: Generator.Element? {
 | 
			
		||||
        return backingArray.first
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public subscript(position: Index) -> Generator.Element {
 | 
			
		||||
        get {
 | 
			
		||||
            return backingArray[position]
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        set {
 | 
			
		||||
            backingArray[position] = newValue
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public subscript(bounds: Range<Index>) -> SubSequence {
 | 
			
		||||
        get {
 | 
			
		||||
            return backingArray[bounds]
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        set {
 | 
			
		||||
            backingArray[bounds] = newValue
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public init(arrayLiteral elements: Element...) {
 | 
			
		||||
        backingArray = elements
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public func generate() -> Generator {
 | 
			
		||||
        return backingArray.generate()
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public mutating func insert(element: Element, replacing replace: Bool = true) {
 | 
			
		||||
        for i in 0..<backingArray.count where backingArray[i] == element {
 | 
			
		||||
            guard replace else { return }
 | 
			
		||||
            
 | 
			
		||||
            backingArray[i] = element
 | 
			
		||||
            
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        backingArray.append(element)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @warn_unused_result
 | 
			
		||||
    public func prefixUpTo(end: Index) -> SubSequence {
 | 
			
		||||
        return backingArray.prefixUpTo(end)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @warn_unused_result
 | 
			
		||||
    public func prefixThrough(position: Index) -> SubSequence {
 | 
			
		||||
        return prefixThrough(position)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @warn_unused_result
 | 
			
		||||
    public func suffixFrom(start: Index) -> SubSequence {
 | 
			
		||||
        return backingArray.suffixFrom(start)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -24,7 +24,7 @@
 | 
			
		||||
 | 
			
		||||
import Foundation
 | 
			
		||||
 | 
			
		||||
protocol ClientOption : CustomStringConvertible, Hashable {
 | 
			
		||||
protocol ClientOption : CustomStringConvertible, Equatable {
 | 
			
		||||
    func getSocketIOOptionValue() -> AnyObject
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -99,10 +99,6 @@ public enum SocketIOClientOption : ClientOption {
 | 
			
		||||
        return description
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public var hashValue: Int {
 | 
			
		||||
        return description.hashValue
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    func getSocketIOOptionValue() -> AnyObject {
 | 
			
		||||
        let value: AnyObject
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user