Compare commits

...
52 Commits
Author SHA1 Message Date
Erik 13176f149c bump version 2015-09-22 16:26:11 -04:00
Erik 3e53228e36 remove print 2015-09-21 14:45:48 -04:00
Erik Little e2cd910fa7 Merge pull request #186 from lightsprint09/travis-test-imporvements
Travis test imporvements
2015-09-19 16:41:35 -04:00
Lukas Schmidt 21ac65733f back to xcodebuild 2015-09-19 21:01:06 +02:00
Lukas Schmidt 6ab7455a08 valid yaml 2015-09-19 20:57:52 +02:00
Lukas Schmidt 7a146bf6ac try using xctool 2015-09-19 20:50:12 +02:00
Lukas Schmidt 0d7d319cc3 remove remote test server option 2015-09-19 20:42:07 +02:00
Lukas Schmidt 14b0022fdc remove node dependencies 2015-09-19 20:41:58 +02:00
Lukas Schmidt 9c16ffade8 xctool not working 2015-09-19 20:32:25 +02:00
Lukas Schmidt 30c1a4df97 parallel test server 2015-09-19 20:28:44 +02:00
Erik 492ae89344 small tweak to readme 2015-09-18 13:31:00 -04:00
Erik Little 7bdf80d133 Merge pull request #185 from socketio/api-cleanup
Api cleanup
2015-09-18 13:29:41 -04:00
Erik 01b88f8e37 fix readme 2015-09-18 13:16:09 -04:00
Erik 9860452814 don't use operator 2015-09-18 13:09:22 -04:00
Erik 835e1c2262 I don't see a need for unowned 2015-09-18 12:54:09 -04:00
Erik ba7ffe6d26 space 2015-09-18 12:46:55 -04:00
Erik 6ed90a3e60 clean up once 2015-09-18 12:45:35 -04:00
Erik d2d9c49414 no need to force unwrap 2015-09-18 12:41:27 -04:00
Erik 4c033f81d6 make final class 2015-09-18 12:31:55 -04:00
Erik b0cf8d2c40 tweaks 2015-09-18 12:28:28 -04:00
Lukas Schmidt 1a48adb03d move out of server dir 2015-09-18 18:23:49 +02:00
Lukas Schmidt 9a39524ba2 npm install before running test server 2015-09-18 18:19:05 +02:00
Lukas Schmidt 5b6b36a2dc travis test 2015-09-18 18:14:12 +02:00
Lukas Schmidt 198f24c684 clean code 2015-09-18 18:09:35 +02:00
Erik f464eba995 tweaks 2015-09-18 11:52:35 -04:00
Erik 0e791176bd fix readme 2015-09-18 11:36:11 -04:00
Erik 243a750377 fix readme 2015-09-18 11:35:29 -04:00
Lukas Schmidt 6cffbc2404 Merge remote-tracking branch 'socketio/master' 2015-09-18 17:34:39 +02:00
Erik a56227d08a merge master 2015-09-18 11:33:07 -04:00
Erik 0233bce881 tweaks to closing 2015-09-18 09:27:14 -04:00
Erik 456406416a other init doesn't exist anymore 2015-09-18 09:02:18 -04:00
Erik 99ed93038f update readme 2015-09-18 09:01:03 -04:00
Erik 9a05f6043b tweaks to once 2015-09-17 23:52:23 -04:00
Erik Little 70c7dacde9 Merge pull request #183 from KevinMartin/patch-1
Adds SocketIOClient#once(event, callback)
2015-09-17 23:22:22 -04:00
Kevin Jose Martin a9b4193fe4 Fix "Variable 'handler' captured by a closure before being initialized" error 2015-09-17 22:06:12 -04:00
Kevin Jose Martin aaaf9dc451 Filter against SocketEventHandler#id 2015-09-17 21:49:18 -04:00
Kevin Jose Martin fe8469cfc6 Add SocketEventHandler#id to filter against 2015-09-17 21:48:09 -04:00
Kevin Jose Martin f5c3a2cac9 Add strict equality and execute "callback" as non-optional 2015-09-17 21:08:37 -04:00
Kevin Jose Martin 7d26bd3ee8 Fix type declarations 2015-09-17 21:00:56 -04:00
Kevin Jose Martin 136847fd77 Fix "Variable used within its own initial value" error 2015-09-17 20:41:34 -04:00
Kevin Jose Martin 9b3f84dcd0 Remove type declarations 2015-09-17 20:33:36 -04:00
Kevin Jose Martin a72f96759e Adds SocketIOClient#once(event, callback)
When the specified event is emitted, the handler deregisters itself.
2015-09-17 18:19:49 -04:00
Erik a81f925671 make note of https 2015-09-17 13:33:37 -04:00
Erik 4997294186 clean up readme 2015-09-17 09:47:02 -04:00
Erik ba5638a109 Revert "tweak to objective-c api"
This reverts commit d0a57ca353.
2015-09-17 09:09:02 -04:00
Erik 978bd2614e bump version 2015-09-17 09:08:58 -04:00
Erik 2f2bd49045 fix socketio/socket.io-client-swift#181 2015-09-17 09:06:09 -04:00
Erik f889d37e9b update readme. This api is probably going to change again 2015-09-16 12:49:25 -04:00
Erik 67afbcbd56 mess around with api 2015-09-16 12:46:19 -04:00
Erik d0a57ca353 tweak to objective-c api 2015-09-16 11:16:12 -04:00
Erik Little 9355fc5077 Update README.md 2015-09-15 18:27:50 -04:00
Lukas Schmidt 6a10f72443 Merge branch 'swift-2' 2015-09-11 10:22:47 +02:00
18 changed files with 221 additions and 166 deletions

No files matched your search

+6 -1
View File
@@ -2,4 +2,9 @@ language: objective-c
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
xcode_scheme: SocketIO-iOS
osx_image: xcode7
script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-iOS -sdk iphonesimulator build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-iOS -sdk iphonesimulator build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
before_install:
install: cd Socket.IO-Test-Server/ && npm install && cd .. && node Socket.IO-Test-Server/main.js &
cache:
directories:
- Socket.IO-Test-Server/node_modules
+19 -21
View File
@@ -12,12 +12,12 @@ socket.on("connect") {data, ack in
}
socket.on("currentAmount") {data, ack in
if let cur = data?[0] as? Double {
if let cur = data[0] as? Double {
socket.emitWithAck("canUpdate", cur)(timeoutAfter: 0) {data in
socket.emit("update", ["amount": cur + 2.50])
}
ack?("Got your currentAmount", "dude")
ack?.with("Got your currentAmount", "dude")
}
}
@@ -26,20 +26,20 @@ socket.connect()
##Objective-C Example
```objective-c
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:nil];
[socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSLog(@"socket connected");
}];
[socket onObjectiveC:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
double cur = [[data objectAtIndex:0] floatValue];
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
});
ack(@[@"Got your currentAmount, ", @"dude"]);
[ack with:@[@"Got your currentAmount, ", @"dude"]];
}];
[socket connect];
@@ -64,10 +64,10 @@ Carthage
-----------------
Add this line to your `Cartfile`:
```
github "socketio/socket.io-client-swift" ~> 3.0.1 # Or latest version
github "socketio/socket.io-client-swift" ~> 3.1.0 # Or latest version
```
Run `carthage update`.
Run `carthage update --platform ios,macosx`.
Manually (iOS 7+)
-----------------
@@ -83,7 +83,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Socket.IO-Client-Swift', '~> 3.0.1' # Or latest version
pod 'Socket.IO-Client-Swift', '~> 3.1.0' # Or latest version
```
Install pods:
@@ -107,9 +107,7 @@ Objective-C:
##API
Constructors
-----------
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values)
`convenience init(socketURL: String, options:NSDictionary?)` - Same as above, but meant for Objective-C. See Objective-C Example.
`init(socketURL: String, opts: NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values) note: If your socket.io server is secure, you need to specify `https` in your socketURL.
Options
-------
@@ -130,16 +128,16 @@ Options
Methods
-------
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.
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.
3. `onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
4. `emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
5. `emit(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
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.
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.
1. `on(event: String, callback: NormalCallback)` - 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.
2. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
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.
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.
8. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
9. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
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.
9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
10. `close()` - Closes the socket. Once a socket is closed it should not be reopened.
11. `reconnect()` - Causes the client to reconnect to the server.
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift"
s.version = "3.0.1"
s.version = "3.1.0"
s.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC
Socket.IO-client for iOS and OS X.
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v3.0.1' }
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v3.1.0' }
s.source_files = "SocketIOClientSwift/**/*.swift"
s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
@@ -83,6 +83,12 @@
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
@@ -162,6 +168,7 @@
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckEmitter.swift; path = SocketIOClientSwift/SocketAckEmitter.swift; sourceTree = "<group>"; };
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; };
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; };
@@ -268,16 +275,16 @@
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
isa = PBXGroup;
children = (
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */,
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */,
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */,
941A4AB91B67A56C00C42318 /* TestKind.swift */,
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
941A4AB91B67A56C00C42318 /* TestKind.swift */,
572EF2291B51F16C00EEBB58 /* Supporting Files */,
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
);
path = "SocketIO-iOSTests";
sourceTree = "<group>";
@@ -327,6 +334,7 @@
5764DF7B1B51F24A004FF46E /* Source */ = {
isa = PBXGroup;
children = (
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */,
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
@@ -582,6 +590,7 @@
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
@@ -607,6 +616,7 @@
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */,
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */,
@@ -635,6 +645,7 @@
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
@@ -654,6 +665,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
);
@@ -666,6 +678,7 @@
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
@@ -691,6 +704,7 @@
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,
@@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
@@ -62,15 +62,18 @@
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
@@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
+5 -3
View File
@@ -1,6 +1,8 @@
var app = require('express')()
var server = app.listen(6979)
var io = require('socket.io')(server)
var app = require('http').createServer()
var io = require('socket.io')(app);
app.listen(6979)
var acknowledgementsEvents = require("./acknowledgementEvents.js")
var emitEvents = require("./emitEvents.js")
var socketEventRegister = require("./socketEventRegister.js")
-1
View File
@@ -9,7 +9,6 @@
"author": "Lukas Schmidt",
"license": "MIT",
"dependencies": {
"express": "^4.13.1",
"socket.io": "^1.3.6"
}
}
+8 -9
View File
@@ -9,8 +9,7 @@
import XCTest
class AbstractSocketTest: XCTestCase {
static let testLocal = false
static let serverURL = AbstractSocketTest.testLocal ? "localhost:6979" : "milkbartube.com:6979"
static let serverURL = "localhost:6979"
static let TEST_TIMEOUT = 8.0
static var socket:SocketIOClient!
var testKind:TestKind?
@@ -45,7 +44,7 @@ class AbstractSocketTest: XCTestCase {
func socketMultipleEmit(testName:String, emitData:Array<AnyObject>, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
callback(result, ack)
if let expection = expection {
expection.fulfill()
@@ -61,12 +60,11 @@ class AbstractSocketTest: XCTestCase {
func socketEmit(testName:String, emitData:AnyObject?, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
callback(result, ack)
if let expection = expection {
expection.fulfill()
}
}
AbstractSocketTest.socket.on(finalTestname + "Return", callback: didGetEmit)
@@ -79,11 +77,12 @@ class AbstractSocketTest: XCTestCase {
waitForExpectationsWithTimeout(SocketEmitTest.TEST_TIMEOUT, handler: nil)
}
func socketAcknwoledgeMultiple(testName:String, Data:Array<AnyObject>, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetResult(result:NSArray?) {
callback(result, nil)
func didGetResult(result: [AnyObject]) {
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
if let expection = expection {
expection.fulfill()
}
@@ -96,8 +95,8 @@ class AbstractSocketTest: XCTestCase {
func socketAcknwoledge(testName:String, Data:AnyObject?, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGet(result:NSArray?) {
callback(result, nil)
func didGet(result:[AnyObject]) {
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
if let expection = expection {
expection.fulfill()
}
+1 -2
View File
@@ -14,9 +14,8 @@ class SocketAckManagerTest: XCTestCase {
func testAddAcks() {
let callbackExpection = self.expectationWithDescription("callbackExpection")
let itemsArray = ["Hi", "ho"]
func callback(items: NSArray?) {
func callback(items: [AnyObject]) {
callbackExpection.fulfill()
items?.isEqualToArray(itemsArray)
}
ackManager.addAck(1, callback: callback)
ackManager.executeAck(1, items: itemsArray)
+37 -37
View File
@@ -14,7 +14,7 @@ class SocketTestCases: NSObject {
static func testBasic(abstractSocketSend:SocketSendFunction) {
let testName = "basicTest"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
}
abstractSocketSend(testName: testName, emitData: nil, callback: didGetResult)
@@ -22,8 +22,8 @@ class SocketTestCases: NSObject {
static func testNull(abstractSocketSend:SocketSendFunction) {
let testName = "testNull"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let _ = result?.firstObject as? NSNull {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let _ = result.first as? NSNull {
}else
{
@@ -35,8 +35,8 @@ class SocketTestCases: NSObject {
static func testBinary(abstractSocketSend:SocketSendFunction) {
let testName = "testBinary"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let data = result?.firstObject as? NSData {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let data = result.first as? NSData {
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
XCTAssertEqual(string, "gakgakgak2")
}else {
@@ -49,8 +49,8 @@ class SocketTestCases: NSObject {
static func testArray(abstractSocketSend:SocketSendFunction) {
let testName = "testArray"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let array = result?.firstObject as? NSArray {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let array = result.first as? NSArray {
XCTAssertEqual(array.count, 2)
XCTAssertEqual((array.firstObject! as! String), "test3")
XCTAssertEqual((array.lastObject! as! String), "test4")
@@ -63,8 +63,8 @@ class SocketTestCases: NSObject {
static func testString(abstractSocketSend:SocketSendFunction) {
let testName = "testString"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let string = result?.firstObject as? String {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let string = result.first as? String {
XCTAssertEqual(string, "polo")
}else {
XCTFail("Should have String as result")
@@ -75,8 +75,8 @@ class SocketTestCases: NSObject {
static func testBool(abstractSocketSend:SocketSendFunction) {
let testName = "testBool"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let bool = result?.firstObject as? NSNumber {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let bool = result.first as? NSNumber {
XCTAssertTrue(bool.boolValue)
}else {
XCTFail("Should have Boolean as result")
@@ -87,8 +87,8 @@ class SocketTestCases: NSObject {
static func testInteger(abstractSocketSend:SocketSendFunction) {
let testName = "testInteger"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let integer = result?.firstObject as? Int {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let integer = result.first as? Int {
XCTAssertEqual(integer, 20)
}else {
XCTFail("Should have Integer as result")
@@ -99,8 +99,8 @@ class SocketTestCases: NSObject {
static func testDouble(abstractSocketSend:SocketSendFunction) {
let testName = "testDouble"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let double = result?.firstObject as? NSNumber {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let double = result.first as? NSNumber {
XCTAssertEqual(double.floatValue, 1.2)
}else {
XCTFail("Should have Double as result")
@@ -113,8 +113,8 @@ class SocketTestCases: NSObject {
let testName = "testJSONWithBuffer"
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let json = result?.firstObject as? NSDictionary {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let json = result.first as? NSDictionary {
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
XCTAssertEqual((json.valueForKey("testNumber")! as! Int), 15)
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
@@ -132,8 +132,8 @@ class SocketTestCases: NSObject {
static func testJSON(abstractSocketSend:SocketSendFunction) {
let testName = "testJSON"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let json = result?.firstObject as? NSDictionary {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let json = result.first as? NSDictionary {
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
XCTAssertEqual(json.valueForKey("testNumber")! as? Int, 15)
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
@@ -151,8 +151,8 @@ class SocketTestCases: NSObject {
static func testUnicode(abstractSocketSend:SocketSendFunction) {
let testName = "testUnicode"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let unicode = result?.firstObject as? String {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
if let unicode = result.first as? String {
XCTAssertEqual(unicode, "🚄")
}else {
XCTFail("Should have String as result")
@@ -163,37 +163,37 @@ class SocketTestCases: NSObject {
static func testMultipleItemsWithBuffer(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
let testName = "testMultipleItemsWithBuffer"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
XCTAssertEqual(result!.count, 5)
if result!.count != 5 {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
XCTAssertEqual(result.count, 5)
if result.count != 5 {
XCTFail("Fatal Fail. Lost some Data")
return
}
if let array = result?.firstObject as? Array<AnyObject> {
if let array = result.first as? Array<AnyObject> {
XCTAssertEqual((array.last! as! Int), 2)
XCTAssertEqual((array.first! as! Int), 1)
}else {
XCTFail("Should have Array as result")
}
if let dict = result?[1] as? NSDictionary {
if let dict = result[1] as? NSDictionary {
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
}else {
XCTFail("Should have NSDictionary as result")
}
if let number = result?[2] as? Int {
if let number = result[2] as? Int {
XCTAssertEqual(number, 25)
}else {
XCTFail("Should have Integer as result")
}
if let string = result?[3] as? String {
if let string = result[3] as? String {
XCTAssertEqual(string, "polo")
}else {
XCTFail("Should have Integer as result")
}
if let data = result?[4] as? NSData {
if let data = result[4] as? NSData {
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
XCTAssertEqual(string, "gakgakgak2")
}else {
@@ -207,36 +207,36 @@ class SocketTestCases: NSObject {
static func testMultipleItems(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
let testName = "testMultipleItems"
func didGetResult(result:NSArray?, ack:AckEmitter?) {
XCTAssertEqual(result!.count, 5)
if result!.count != 5 {
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
XCTAssertEqual(result.count, 5)
if result.count != 5 {
XCTFail("Fatal Fail. Lost some Data")
return
}
if let array = result?.firstObject as? Array<AnyObject> {
if let array = result.first as? Array<AnyObject> {
XCTAssertEqual((array.last! as! Int), 2)
XCTAssertEqual((array.first! as! Int), 1)
}else {
XCTFail("Should have Array as result")
}
if let dict = result?[1] as? NSDictionary {
if let dict = result[1] as? NSDictionary {
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
}else {
XCTFail("Should have NSDictionary as result")
}
if let number = result?[2] as? Int {
if let number = result[2] as? Int {
XCTAssertEqual(number, 25)
}else {
XCTFail("Should have Integer as result")
}
if let string = result?[3] as? String {
if let string = result[3] as? String {
XCTAssertEqual(string, "polo")
}else {
XCTFail("Should have Integer as result")
}
if let bool = result?[4] as? NSNumber {
if let bool = result[4] as? NSNumber {
XCTAssertFalse(bool.boolValue)
}else {
XCTFail("Should have NSNumber as result")
@@ -0,0 +1,43 @@
//
// SocketAckEmitter.swift
// Socket.IO-Client-Swift
//
// Created by Erik Little on 9/16/15.
//
// 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.
import Foundation
public final class SocketAckEmitter: NSObject {
let socket: SocketIOClient
let ackNum: Int
init(socket: SocketIOClient, ackNum: Int) {
self.socket = socket
self.ackNum = ackNum
}
public func with(items: AnyObject...) {
socket.emitAck(ackNum, withItems: items)
}
public func with(items: [AnyObject]) {
socket.emitAck(ackNum, withItems: items)
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ struct SocketAckManager {
acks.insert(SocketAck(ack: ack, callback: callback))
}
mutating func executeAck(ack: Int, items: [AnyObject]?) {
mutating func executeAck(ack: Int, items: [AnyObject]) {
let callback = acks.remove(SocketAck(ack: ack))
dispatch_async(dispatch_get_main_queue()) {
+24 -18
View File
@@ -99,6 +99,19 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
deinit {
Logger.log("Engine is being deinit", type: logType)
}
private func checkIfMessageIsBase64Binary(var message: String) {
if message.hasPrefix("b4") {
// binary in base64 string
message.removeRange(Range<String.Index>(start: message.startIndex,
end: message.startIndex.advancedBy(2)))
if let data = NSData(base64EncodedString: message,
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) {
client?.parseBinaryData(data)
}
}
}
public func close(fast fast: Bool) {
Logger.log("Engine is being closed. Fast: %@", type: logType, args: fast)
@@ -364,19 +377,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
}
}
private func checkIfMessageIsBase64Binary(var message: String) {
if message.hasPrefix("b4") {
// binary in base64 string
message.removeRange(Range<String.Index>(start: message.startIndex,
end: message.startIndex.advancedBy(2)))
if let data = NSData(base64EncodedString: message,
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) {
client?.parseBinaryData(data)
}
}
}
private func handleMessage(message: String) {
client?.parseSocketMessage(message)
}
@@ -492,11 +492,17 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
var reader = SocketStringReader(message: str)
while reader.hasNext {
let n = reader.readUntilStringOccurence(":")
let str = reader.read(Int(n)!)
dispatch_async(handleQueue) {
self.parseEngineMessage(str, fromPolling: true)
if let n = Int(reader.readUntilStringOccurence(":")) {
let str = reader.read(n)
dispatch_async(handleQueue) {
self.parseEngineMessage(str, fromPolling: true)
}
} else {
dispatch_async(handleQueue) {
self.parseEngineMessage(str, fromPolling: true)
}
break
}
}
}
+9 -23
View File
@@ -24,37 +24,23 @@
import Foundation
private func emitAckCallback(socket: SocketIOClient?, num: Int?)
(items: AnyObject...) -> Void {
socket?.emitAck(num ?? -1, withItems: items)
}
private func emitAckCallbackObjectiveC(socket: SocketIOClient?, num: Int?)
(items: NSArray) -> Void {
socket?.emitAck(num ?? -1, withItems: items as [AnyObject])
private func emitAckCallback(socket: SocketIOClient, num: Int?) -> SocketAckEmitter? {
return num != nil ? SocketAckEmitter(socket: socket, ackNum: num!) : nil
}
struct SocketEventHandler {
let event: String
let callback: NormalCallback?
let callBackObjectiveC: NormalCallbackObjectiveC?
let callback: NormalCallback
let id: NSUUID
init(event: String, callback: NormalCallback) {
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
self.event = event
self.id = id
self.callback = callback
self.callBackObjectiveC = nil
}
init(event: String, callback: NormalCallbackObjectiveC) {
self.event = event
self.callback = nil
self.callBackObjectiveC = callback
}
func executeCallback(items:NSArray? = nil, withAck ack:Int? = nil, withAckType type:Int? = nil,
withSocket socket:SocketIOClient? = nil) {
self.callback != nil ?
self.callback?(items, emitAckCallback(socket, num: ack))
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
func executeCallback(items: [AnyObject], withAck ack: Int? = nil, withAckType type: Int? = nil,
withSocket socket: SocketIOClient) {
self.callback(items, emitAckCallback(socket, num: ack))
}
}
+21 -16
View File
@@ -133,12 +133,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Will turn off automatic reconnects.
Pass true to fast if you're closing from a background task
*/
public func close(fast fast: Bool) {
public func close() {
Logger.log("Closing socket", type: logType)
reconnects = false
status = SocketIOClientStatus.Closed
engine?.close(fast: fast)
didDisconnect("Closed")
}
/**
@@ -151,8 +150,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
/**
Connect to the server. If we aren't connected after timeoutAfter, call handler
*/
public func connect(timeoutAfter timeoutAfter:Int,
withTimeoutHandler handler:(() -> Void)?) {
public func connect(timeoutAfter timeoutAfter: Int,
withTimeoutHandler handler: (() -> Void)?) {
assert(timeoutAfter >= 0, "Invalid timeout: \(timeoutAfter)")
guard status != .Connected else {
@@ -211,7 +210,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
// Don't handle as internal because something crazy could happen where
// we disconnect before it's handled
handleEvent("connect", data: nil, isInternalMessage: false)
handleEvent("connect", data: [], isInternalMessage: false)
}
func didDisconnect(reason: String) {
@@ -222,7 +221,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Logger.log("Disconnected: %@", type: logType, args: reason)
status = .Closed
reconnects = false
// Make sure the engine is actually dead.
@@ -241,8 +239,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
/**
Same as close
*/
public func disconnect(fast fast: Bool) {
close(fast: fast)
public func disconnect() {
close()
}
/**
@@ -333,13 +331,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Logger.log("Handling ack: %@ with data: %@", type: logType, args: ack, data ?? "")
ackHandlers.executeAck(ack,
items: (data as? [AnyObject]?) ?? (data != nil ? [data!] : nil))
items: (data as? [AnyObject]) ?? (data != nil ? [data!] : []))
}
/**
Causes an event to be handled. Only use if you know what you're doing.
*/
public func handleEvent(event: String, data: [AnyObject]?, isInternalMessage: Bool,
public func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool,
wantsAck ack: Int? = nil) {
guard status == .Connected || isInternalMessage else {
return
@@ -360,7 +358,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
}
} else {
dispatch_async(handleQueue) {
handler.executeCallback(data)
handler.executeCallback(data, withAck: ack, withSocket: self)
}
}
}
@@ -415,12 +413,19 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
}
/**
Adds a handler for an event.
Adds a single-use handler for an event.
*/
public func onObjectiveC(event: String, callback: NormalCallbackObjectiveC) {
Logger.log("Adding handler for event: %@", type: logType, args: event)
public func once(event: String, callback: NormalCallback) {
Logger.log("Adding once handler for event: %@", type: logType, args: event)
let handler = SocketEventHandler(event: event, callback: callback)
let id = NSUUID()
let handler = SocketEventHandler(event: event, id: id) {[weak self] data, ack in
guard let this = self else {return}
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
callback(data, ack)
}
handlers.append(handler)
}
+2 -2
View File
@@ -31,7 +31,7 @@ class SocketParser {
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) {
guard isCorrectNamespace(p.nsp, socket) else { return }
socket.handleEvent(p.event, data: p.args,
socket.handleEvent(p.event, data: p.args ?? [],
isInternalMessage: false, wantsAck: p.id)
}
@@ -166,7 +166,7 @@ class SocketParser {
packet.fillInPlaceholders()
if packet.type != .BinaryAck {
socket.handleEvent(packet.event, data: packet.args,
socket.handleEvent(packet.event, data: packet.args ?? [],
isInternalMessage: false, wantsAck: packet.id)
} else {
socket.handleAck(packet.id, data: packet.args)
+3 -6
View File
@@ -24,10 +24,7 @@
import Foundation
public typealias AckCallback = (NSArray?) -> Void
public typealias AckEmitter = (AnyObject...) -> Void
public typealias AckEmitterObjectiveC = (NSArray) -> Void
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
public typealias NormalCallbackObjectiveC = (NSArray?, AckEmitterObjectiveC?) -> Void
public typealias OnAckCallback = (timeoutAfter:UInt64, callback:AckCallback) -> Void
public typealias AckCallback = ([AnyObject]) -> Void
public typealias NormalCallback = ([AnyObject], SocketAckEmitter?) -> Void
public typealias OnAckCallback = (timeoutAfter: UInt64, callback: AckCallback) -> Void
+15 -16
View File
@@ -29,8 +29,8 @@ internal class SwiftRegex: NSObject, BooleanType {
NSRegularExpressionOptions.DotMatchesLineSeparators)
swiftRegexCache[pattern] = regex
self.regex = regex
} catch let error1 as NSError {
SwiftRegex.failure("Error in pattern: \(pattern) - \(error1)")
} catch let error as NSError {
SwiftRegex.failure("Error in pattern: \(pattern) - \(error)")
self.regex = NSRegularExpression()
}
}
@@ -46,7 +46,7 @@ internal class SwiftRegex: NSObject, BooleanType {
}
private final func substring(range: NSRange) -> String? {
if ( range.location != NSNotFound ) {
if range.location != NSNotFound {
return (target as NSString).substringWithRange(range)
} else {
return nil
@@ -70,20 +70,19 @@ internal class SwiftRegex: NSObject, BooleanType {
NSMatchingOptions.WithoutAnchoringBounds, range: targetRange))
}
private func groupsForMatch(match: NSTextCheckingResult!) -> [String]? {
if match != nil {
var groups = [String]()
for groupno in 0...regex.numberOfCaptureGroups {
if let group = substring(match.rangeAtIndex(groupno)) {
groups += [group]
} else {
groups += ["_"] // avoids bridging problems
}
}
return groups
} else {
private func groupsForMatch(match: NSTextCheckingResult?) -> [String]? {
guard let match = match else {
return nil
}
var groups = [String]()
for groupno in 0...regex.numberOfCaptureGroups {
if let group = substring(match.rangeAtIndex(groupno)) {
groups += [group]
} else {
groups += ["_"] // avoids bridging problems
}
}
return groups
}
subscript(groupno: Int) -> String? {
@@ -124,7 +123,7 @@ internal class SwiftRegex: NSObject, BooleanType {
}
func allGroups() -> [[String]?] {
return matchResults().map {self.groupsForMatch($0)}
return matchResults().map { self.groupsForMatch($0) }
}
func dictionary(options: NSMatchingOptions!) -> Dictionary<String,String> {