Skip to content

Commit

Permalink
Merge pull request #6 from marinbenc/swift-5
Browse files Browse the repository at this point in the history
Add Swift 5 support
  • Loading branch information
marinbenc authored Apr 19, 2019
2 parents 2db36e1 + 5ab6dba commit 2add857
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ target 'scaledrone-swift' do
use_frameworks!

# Pods for scaledrone-swift
pod 'Starscream', '~> 2.1.1'
pod 'Starscream', '~> 3.1.0'
end
10 changes: 5 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PODS:
- Starscream (2.1.1)
- Starscream (3.1.0)

DEPENDENCIES:
- Starscream (~> 2.1.1)
- Starscream (~> 3.1.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Starscream

SPEC CHECKSUMS:
Starscream: 142bd8ef24592d985daee9fa48c936070b85b15f
Starscream: 08172b481e145289c4930cb567230fb55897cfa4

PODFILE CHECKSUM: 599cfa72f558a49cc26af9863fd342fb6983e4fc
PODFILE CHECKSUM: 45b3febbccd7bb7c2bf35eb2f8f29b31f482f767

COCOAPODS: 1.5.3
COCOAPODS: 1.6.1
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ This project is still a work in progress, pull requests and issues are very welc
Check out [Get Started](http://cocoapods.org/) tab on [cocoapods.org](http://cocoapods.org/).

To use Scaledrone in your project add the following 'Podfile' to your project

```ruby
pod 'Scaledrone', '~> 0.4.0'
pod 'Scaledrone', '~> 0.5.0'
```

Then run:
Expand Down Expand Up @@ -42,23 +43,23 @@ After you are connected, there are some delegate methods that we need to impleme
#### scaledroneDidConnect

```swift
func scaledroneDidConnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidConnect(scaledrone: Scaledrone, error: Error?) {
print("Connected to Scaledrone")
}
```

#### scaledroneDidReceiveError

```swift
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone error", error ?? "")
}
```

#### scaledroneDidDisconnect

```swift
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone disconnected", error ?? "")
}
```
Expand All @@ -79,7 +80,7 @@ scaledrone.authenticate(jwt: "jwt_string")
#### scaledroneDidAuthenticate

```swift
func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone authenticated", error ?? "")
}
```
Expand All @@ -104,7 +105,7 @@ room.delegate = self
#### scaledroneRoomDidConnect

```swift
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: NSError?) {
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: Error?) {
print("Scaledrone connected to room", room.name, error ?? "")
}
```
Expand Down Expand Up @@ -237,21 +238,21 @@ class ViewController: UIViewController, ScaledroneDelegate, ScaledroneRoomDelega
scaledrone.connect()
}

func scaledroneDidConnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidConnect(scaledrone: Scaledrone, error: Error?) {
print("Connected to Scaledrone channel", scaledrone.clientID)
let room = scaledrone.subscribe(roomName: "notifications")
room.delegate = self
}

func scaledroneDidReceiveError(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone error")
}

func scaledroneDidDisconnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone disconnected")
}

func scaledroneRoomDidConnect(room: ScaledroneRoom, error: NSError?) {
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: Error?) {
print("Scaledrone connected to room", room.name)
}

Expand All @@ -263,6 +264,10 @@ class ViewController: UIViewController, ScaledroneDelegate, ScaledroneRoomDelega

For a longer example see the `ViewController.swift` file.

## Migration notes for Scaledrone 0.5.0:

Scaledrone 0.5.0 removes the use of `NSError` in favor of `Error` in the delegate methods, and adds support for Swift 5.

## Todo:

* Automatic reconnection
6 changes: 3 additions & 3 deletions Scaledrone.podspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Pod::Spec.new do |s|
s.name = 'Scaledrone'
s.version = '0.4.0'
s.version = '0.5.0'
s.summary = 'Scaledrone Swift Client'
s.homepage = 'https://github.com/scaledrone/scaledrone-swift'
s.license = 'Apache-2.0'
s.author = { "Scaledrone" => "[email protected]" }
s.source = { git: "https://github.com/ScaleDrone/Scaledrone-Swift.git" }
s.source = { git: "https://github.com/scaledrone/Scaledrone-Swift.git" }
s.requires_arc = true
s.source_files = 'scaledrone-swift/Scaledrone.swift'

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'

s.dependency "Starscream", "~> 2.1.1"
s.dependency "Starscream", "~> 3.1.0"
end
31 changes: 25 additions & 6 deletions scaledrone-swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = Scaledrone;
TargetAttributes = {
B6F3B8401F3F69CE0063002B = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = B6F3B83C1F3F69CE0063002B /* Build configuration list for PBXProject "scaledrone-swift" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -185,7 +186,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-scaledrone-swift/Pods-scaledrone-swift-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-scaledrone-swift/Pods-scaledrone-swift-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -194,7 +195,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-scaledrone-swift/Pods-scaledrone-swift-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-scaledrone-swift/Pods-scaledrone-swift-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -236,20 +237,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -286,20 +296,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -334,7 +353,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "scaledrone.scaledrone-swift";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -347,7 +366,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "scaledrone.scaledrone-swift";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion scaledrone-swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
2 changes: 1 addition & 1 deletion scaledrone-swift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>0.5.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
32 changes: 16 additions & 16 deletions scaledrone-swift/Scaledrone.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Starscream

public protocol ScaledroneDelegate: class {
func scaledroneDidConnect(scaledrone: Scaledrone, error: NSError?)
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: NSError?)
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: NSError?)
func scaledroneDidConnect(scaledrone: Scaledrone, error: Error?)
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: Error?)
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: Error?)
}

public protocol ScaledroneAuthenticateDelegate: class {
func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: NSError?)
func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: Error?)
}

public protocol ScaledroneRoomDelegate: class {
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: NSError?)
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: Error?)
func scaledroneRoomDidReceiveMessage(room: ScaledroneRoom, message: Any, member: ScaledroneMember?)
}

Expand All @@ -25,13 +25,13 @@ public class Scaledrone: WebSocketDelegate {

private typealias Callback = ([String:Any]) -> Void

private let socket:WebSocket
private var callbacks:[Int:Callback] = [:]
private var callbackId:Int = 0
private var rooms:[String:ScaledroneRoom] = [:]
private let channelID:String
private var data:Any?
public var clientID:String = ""
private let socket: WebSocket
private var callbacks: [Int: Callback] = [:]
private var callbackId: Int = 0
private var rooms: [String: ScaledroneRoom] = [:]
private let channelID: String
private var data: Any?
public var clientID: String = ""

private typealias RoomName = String
private var nextHistoryIndex: [RoomName: Int] = [:]
Expand Down Expand Up @@ -79,7 +79,7 @@ public class Scaledrone: WebSocketDelegate {

// MARK: Websocket Delegate Methods.

public func websocketDidConnect(socket: WebSocket) {
public func websocketDidConnect(socket: WebSocketClient) {
var msg = [
"type": "handshake",
"channel": self.channelID,
Expand All @@ -94,11 +94,11 @@ public class Scaledrone: WebSocketDelegate {
self.send(msg)
}

public func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
public func websocketDidDisconnect(socket: WebSocketClient, error: Error?) {
delegate?.scaledroneDidDisconnect(scaledrone: self, error: error)
}

public func websocketDidReceiveMessage(socket: WebSocket, text: String) {
public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
var dic = convertJSONMessageToDictionary(text: text)

if let error = dic["error"] as? String {
Expand Down Expand Up @@ -177,7 +177,7 @@ public class Scaledrone: WebSocketDelegate {
room.delegate?.scaledroneRoomDidReceiveMessage(room: room, message: messageDic["message"] as Any, member: member)
}

public func websocketDidReceiveData(socket: WebSocket, data: Data) {
public func websocketDidReceiveData(socket: WebSocketClient, data: Data) {
print("Should not have received any data: \(data.count)")
}

Expand Down
12 changes: 6 additions & 6 deletions scaledrone-swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ViewController: UIViewController, ScaledroneDelegate, ScaledroneAuthentica
scaledrone.connect()
}

func scaledroneDidConnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidConnect(scaledrone: Scaledrone, error: Error?) {
if (error != nil) {
print(error!);
}
Expand All @@ -25,21 +25,21 @@ class ViewController: UIViewController, ScaledroneDelegate, ScaledroneAuthentica
room2.observableDelegate = self
}

func scaledroneDidReceiveError(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidReceiveError(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone error", error ?? "")
}

func scaledroneDidDisconnect(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidDisconnect(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone disconnected", error ?? "")
}

func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: NSError?) {
func scaledroneDidAuthenticate(scaledrone: Scaledrone, error: Error?) {
print("Scaledrone authenticated", error ?? "")
}

// Rooms

func scaledroneRoomDidConnect(room: ScaledroneRoom, error: NSError?) {
func scaledroneRoomDidConnect(room: ScaledroneRoom, error: Error?) {
print("Scaledrone connected to room", room.name, error ?? "")
scaledrone.publish(message: "Hello from Swift", room: room.name)

Expand All @@ -49,7 +49,7 @@ class ViewController: UIViewController, ScaledroneDelegate, ScaledroneAuthentica

func scaledroneRoomDidReceiveMessage(room: ScaledroneRoom, message: Any, member: ScaledroneMember?) {
if member != nil {
print("Received message from member:", member?.description)
print("Received message from member:", member?.description ?? "")
}
if let message = message as? [String : Any] {
print("Received a dictionary:", message)
Expand Down

0 comments on commit 2add857

Please sign in to comment.