Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-4760] Min iOS 14 + Idiomatic Public Swift Interface #1955

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Ably-SoakTest-AppUITests/SoakTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class SoakTest: XCTestCase {
let internalQueue = DispatchQueue(label: "io.ably.soakTest.internal.\(i)")

queue.async {
let options: ARTClientOptions = {
let options: ClientOptions = {
if true.times(1, outOf: 2) {
return ARTClientOptions(key: "fake:key")
return ClientOptions(key: "fake:key")
} else {
let options = ARTClientOptions()
let options = ClientOptions()
options.authUrl = NSURL(string: "http://fakeauth.com") as URL?
return options
}
Expand All @@ -43,11 +43,11 @@ class SoakTest: XCTestCase {
options.dispatchQueue = queue
options.internalDispatchQueue = internalQueue
options.testOptions.transportFactory = SoakTestRealtimeTransportFactory()
let realtime = ARTRealtime(options: options)
let realtime = Realtime(options: options)
realtime.internal.setReachabilityClass(SoakTestReachability.self)

realtime.connection.on { state in
print("got connection notification; error: \(String(describing: state?.reason))")
print("got connection notification; error: \(String(describing: state.reason))")
}

realtimeOperations(realtime: realtime, queue: queue, shouldStop: shouldStop.get)
Expand Down Expand Up @@ -91,7 +91,7 @@ struct SyncValue<T> {
}
}

func realtimeOperations(realtime: ARTRealtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) {
func realtimeOperations(realtime: Realtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) {
if shouldStop() {
return
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func realtimeOperations(realtime: ARTRealtime, queue: DispatchQueue, shouldStop:
}
}

func channelsOperations(realtime: ARTRealtime, queue: DispatchQueue) {
func channelsOperations(realtime: Realtime, queue: DispatchQueue) {
queue.afterSeconds(between: 0.1 ... 1.0) {
if realtime.connection.state == .closed {
return
Expand Down Expand Up @@ -180,7 +180,7 @@ func channelsOperations(realtime: ARTRealtime, queue: DispatchQueue) {
}
}

func presenceCycle(channel: ARTRealtimeChannel, queue: DispatchQueue) {
func presenceCycle(channel: RealtimeChannel, queue: DispatchQueue) {
let client = "presenceClient.\(nextGlobalSerial())"
channel.presence.enterClient(client, data: randomMessageData()) { error in
print("\(channel.name): got enter ack; error: \(String(describing: error))")
Expand All @@ -206,7 +206,7 @@ func presenceCycle(channel: ARTRealtimeChannel, queue: DispatchQueue) {
}
}

extension ARTRealtimeChannels: Sequence {
extension RealtimeChannels: Sequence {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self.iterate())
}
Expand Down
4 changes: 2 additions & 2 deletions Ably-SoakTest-AppUITests/SoakTestReachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class SoakTestReachability : NSObject, ARTReachability {
let queue: DispatchQueue
var callback: ((Bool) -> Void)?
var isReachable = true

required init(logger: ARTLog, queue: DispatchQueue) {
required init(logger: InternalLog, queue: DispatchQueue) {
self.queue = queue
super.init()
waitAndToggle()
Expand Down
6 changes: 3 additions & 3 deletions Ably-SoakTest-AppUITests/SoakTestURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Ably.Private

class SoakTestURLSession : NSObject, ARTURLSession {
let queue: DispatchQueue
var cancellables: [ARTCancellable] = []
var cancellables: [Cancellable] = []

required init(_ queue: DispatchQueue) {
self.queue = queue
}

func get(_ request: URLRequest, completion callback: @escaping (HTTPURLResponse?, Data?, Error?) -> Void) -> ARTCancellable & NSObjectProtocol {
func get(_ request: URLRequest, completion callback: @escaping (HTTPURLResponse?, Data?, Error?) -> Void) -> Cancellable & NSObjectProtocol {
let cancellable = CancellableInQueue(queue: queue)
cancellables.append(cancellable)

Expand Down Expand Up @@ -62,7 +62,7 @@ class SoakTestURLSession : NSObject, ARTURLSession {
}
}

class CancellableInQueue : NSObject, ARTCancellable {
class CancellableInQueue : NSObject, Cancellable {
let queue: DispatchQueue
var cancelled = false

Expand Down
40 changes: 19 additions & 21 deletions Ably-SoakTest-AppUITests/SoakTestWebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class SoakTestWebSocketFactory: WebSocketFactory {
}

class SoakTestRealtimeTransportFactory: RealtimeTransportFactory {
func transport(withRest rest: ARTRestInternal, options: ARTClientOptions, resumeKey: String?, connectionSerial: NSNumber?, logger: InternalLog) -> ARTRealtimeTransport {
func transport(withRest rest: ARTRestInternal, options: ClientOptions, resumeKey: String?, logger: InternalLog) -> ARTRealtimeTransport {
return ARTWebSocketTransport(
rest: rest,
options: options,
resumeKey: resumeKey,
connectionSerial: connectionSerial,
logger: logger,
webSocketFactory: SoakTestWebSocketFactory()
)
Expand All @@ -44,7 +43,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {

func open() {
readyState = .connecting
delegateDispatchQueue!.afterSeconds(between: 0.1 ... ARTDefault.realtimeRequestTimeout() + 1.0) {
delegateDispatchQueue!.afterSeconds(between: 0.1 ... Default.realtimeRequestTimeout() + 1.0) {
if true.times(9, outOf: 10) {
self.readyState = .open
self.delegate?.webSocketDidOpen?(self)
Expand All @@ -68,7 +67,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
self.sendHeartbeats()
} else {
self.messageToClient(action: .error) { m in
m.error = ARTErrorInfo.create(from: fakeError)
m.error = ErrorInfo.create(from: fakeError)
}
}
}
Expand Down Expand Up @@ -97,15 +96,14 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
}
}

func protocolMessage(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) -> ARTProtocolMessage {
return ARTProtocolMessage.build(action: action) { m in
m.connectionSerial = self.nextConnectionSerial()
func protocolMessage(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) -> ProtocolMessage {
return ProtocolMessage.build(action: action) { m in
m.timestamp = Date()
setUp(m)
}
}

func messageToClient(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) {
func messageToClient(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) {
let message = protocolMessage(action: action, setUp: setUp)
self.delegate?.webSocket?(self, didReceiveMessage: message)
}
Expand Down Expand Up @@ -139,7 +137,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
self.messageToClient(action: .nack) { m in
m.msgSerial = self.pendingSerials.first!
m.count = Int32(self.pendingSerials.count)
m.error = ARTErrorInfo.create(from: fakeError)
m.error = ErrorInfo.create(from: fakeError)
}
}
self.pendingSerials.removeAll()
Expand Down Expand Up @@ -170,7 +168,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
if true.times(1, outOf: 10) {
self.messageToClient(action: .error) { m in
m.channel = message.channel
m.error = ARTErrorInfo.create(from: fakeError)
m.error = ErrorInfo.create(from: fakeError)
}
return
}
Expand Down Expand Up @@ -201,7 +199,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
self.messageToClient(action: .detached) { m in
m.channel = message.channel
if true.times(1, outOf: 5) {
m.error = ARTErrorInfo.create(from: fakeError)
m.error = ErrorInfo.create(from: fakeError)
}
}

Expand All @@ -224,7 +222,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {

var serialForAttachedChannel: [String: Int64] = [:]

func nextMessageToClient(forChannel channel: String, action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) {
func nextMessageToClient(forChannel channel: String, action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) {
guard var channelSerial = self.serialForAttachedChannel[channel] else {
return
}
Expand All @@ -242,7 +240,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
doIfStillOpen(afterSecondsBetween: 0.1 ... 2.0) {
self.nextMessageToClient(forChannel: channel, action: .message) { m in
m.id = "message.\(nextGlobalSerial())"
m.messages = [ARTMessage(
m.messages = [Message(
name: "fakeMessage",
data: randomMessageData()
)]
Expand All @@ -254,7 +252,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {

func sendPresenceMessages(channel: String) {
doIfStillOpen(afterSecondsBetween: 0.1 ... 2.0) {
let presence = ARTPresenceMessage()
let presence = PresenceMessage()
presence.clientId = "someone.\(nextGlobalSerial())"
presence.data = randomMessageData()
presence.action = .enter
Expand All @@ -272,7 +270,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {

func updatePresence(channel: String, clientId: String) {
doIfStillOpen(afterSecondsBetween: 0.1 ... 10.0) {
let presence = ARTPresenceMessage()
let presence = PresenceMessage()
presence.clientId = clientId

if true.times(3, outOf: 4) {
Expand Down Expand Up @@ -319,7 +317,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket {
self.messageToClient(action: .sync) { m in
m.channelSerial = "somethingsomething:\(cursor)"
m.presence = page.map { member in
let message = ARTPresenceMessage()
let message = PresenceMessage()
message.clientId = member
message.action = .present
return message
Expand Down Expand Up @@ -351,8 +349,8 @@ extension String {

let fakeError = "fake error for soak test".asError()

func authError() -> ARTErrorInfo {
return ARTErrorInfo.create(from: "fake auth error".asError(code: 40140))
func authError() -> ErrorInfo {
return ErrorInfo.create(from: "fake auth error".asError(code: 40140))
}

func serialSequence(label: String, first: Int64 = 0) -> (() -> Int64) {
Expand All @@ -371,9 +369,9 @@ func serialSequence(label: String, first: Int64 = 0) -> (() -> Int64) {

let nextGlobalSerial = serialSequence(label: "globalSerial")

extension ARTProtocolMessage {
class func build(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void) -> ARTProtocolMessage {
let m = ARTProtocolMessage()
extension ProtocolMessage {
class func build(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void) -> ProtocolMessage {
let m = ProtocolMessage()
m.action = action
m.id = "fakeProtocolMessage.\(nextGlobalSerial())"
setUp(m)
Expand Down
4 changes: 2 additions & 2 deletions Ably.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/ably/ably-cocoa.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/ablyrealtime'
s.documentation_url = "https://www.ably.io/documentation"
s.ios.deployment_target = '10.0'
s.tvos.deployment_target = '10.0'
s.ios.deployment_target = '14.0'
s.tvos.deployment_target = '14.0'
s.osx.deployment_target = '10.12'
s.requires_arc = true
s.swift_version = '5.0'
Expand Down
Loading
Loading