|
24 | 24 |
|
25 | 25 | import Foundation |
26 | 26 |
|
27 | | -protocol ClientOptions {} |
| 27 | +protocol ClientOption: CustomStringConvertible, Hashable { |
| 28 | + func getSocketIOOptionValue() -> AnyObject? |
| 29 | +} |
28 | 30 |
|
29 | | -public enum SocketIOClientOption: CustomStringConvertible, Hashable, ClientOptions { |
| 31 | +public enum SocketIOClientOption: ClientOption { |
30 | 32 | case ConnectParams([String: AnyObject]) |
31 | 33 | case Cookies([NSHTTPCookie]) |
32 | 34 | case ExtraHeaders([String: String]) |
@@ -98,44 +100,44 @@ public enum SocketIOClientOption: CustomStringConvertible, Hashable, ClientOptio |
98 | 100 | func getSocketIOOptionValue() -> AnyObject? { |
99 | 101 | return Mirror(reflecting: self).children.first?.value as? AnyObject |
100 | 102 | } |
| 103 | +} |
| 104 | + |
| 105 | +public func ==(lhs: SocketIOClientOption, rhs: SocketIOClientOption) -> Bool { |
| 106 | + return lhs.description == rhs.description |
| 107 | +} |
| 108 | + |
| 109 | +extension Set where Element: ClientOption { |
| 110 | + mutating func insertIgnore(element: Element) { |
| 111 | + let (insertType, _) = Mirror(reflecting: element).children.first! |
| 112 | + for item in self { |
| 113 | + let (name, _) = Mirror(reflecting: item).children.first! |
| 114 | + if insertType == name { |
| 115 | + return |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + self.insert(element) |
| 120 | + } |
101 | 121 |
|
102 | 122 | static func NSDictionaryToSocketOptionsSet(dict: NSDictionary) -> Set<SocketIOClientOption> { |
103 | 123 | var options = Set<SocketIOClientOption>() |
104 | | - |
| 124 | + |
105 | 125 | for (rawKey, value) in dict { |
106 | | - if let key = rawKey as? String, opt = keyValueToSocketIOClientOption(key, value: value) { |
| 126 | + if let key = rawKey as? String, opt = SocketIOClientOption.keyValueToSocketIOClientOption(key, value: value) { |
107 | 127 | options.insert(opt) |
108 | 128 | } |
109 | 129 | } |
110 | 130 |
|
111 | 131 | return options |
112 | 132 | } |
113 | 133 |
|
114 | | - static func SocketOptionsSetToNSDictionary(set: Set<SocketIOClientOption>) -> NSDictionary { |
| 134 | + func SocketOptionsSetToNSDictionary() -> NSDictionary { |
115 | 135 | let options = NSMutableDictionary() |
116 | 136 |
|
117 | | - for option in set { |
| 137 | + for option in self { |
118 | 138 | options[option.description] = option.getSocketIOOptionValue() |
119 | 139 | } |
120 | 140 |
|
121 | 141 | return options |
122 | 142 | } |
123 | 143 | } |
124 | | - |
125 | | -public func ==(lhs: SocketIOClientOption, rhs: SocketIOClientOption) -> Bool { |
126 | | - return lhs.description == rhs.description |
127 | | -} |
128 | | - |
129 | | -extension Set where Element: ClientOptions { |
130 | | - mutating func insertIgnore(element: Element) { |
131 | | - let (insertType, _) = Mirror(reflecting: element).children.first! |
132 | | - for item in self { |
133 | | - let (name, _) = Mirror(reflecting: item).children.first! |
134 | | - if insertType == name { |
135 | | - return |
136 | | - } |
137 | | - } |
138 | | - |
139 | | - self.insert(element) |
140 | | - } |
141 | | -} |
|
0 commit comments