Skip to content

Commit 51fdd0f

Browse files
author
Daniel Browne
committed
Move Objective-C interop code to discrete source files
1 parent d49d20f commit 51fdd0f

9 files changed

+236
-229
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Foundation
2+
3+
public extension AuthMethod {
4+
func toObjc() -> OCAuthMethod {
5+
switch self {
6+
case let .endpoint(authEndpoint):
7+
return OCAuthMethod(authEndpoint: authEndpoint)
8+
9+
case let .authRequestBuilder(authRequestBuilder):
10+
return OCAuthMethod(authRequestBuilder: authRequestBuilder)
11+
12+
case let .inline(secret):
13+
return OCAuthMethod(secret: secret)
14+
15+
case let .authorizer(authorizer):
16+
return OCAuthMethod(authorizer: authorizer)
17+
18+
case .noMethod:
19+
return OCAuthMethod(type: 4)
20+
}
21+
}
22+
23+
static func fromObjc(source: OCAuthMethod) -> AuthMethod {
24+
switch source.type {
25+
case 0: return AuthMethod.endpoint(authEndpoint: source.authEndpoint!)
26+
case 1: return AuthMethod.authRequestBuilder(authRequestBuilder: source.authRequestBuilder!)
27+
case 2: return AuthMethod.inline(secret: source.secret!)
28+
case 3: return AuthMethod.authorizer(authorizer: source.authorizer!)
29+
case 4: return AuthMethod.noMethod
30+
default: return AuthMethod.noMethod
31+
}
32+
}
33+
}

Sources/ObjC/OCAuthMethod.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Foundation
2+
3+
@objcMembers
4+
@objc public class OCAuthMethod: NSObject {
5+
var type: Int
6+
var secret: String?
7+
var authEndpoint: String?
8+
var authRequestBuilder: AuthRequestBuilderProtocol?
9+
var authorizer: Authorizer?
10+
11+
public init(type: Int) {
12+
self.type = type
13+
}
14+
15+
public init(authEndpoint: String) {
16+
self.type = 0
17+
self.authEndpoint = authEndpoint
18+
}
19+
20+
public init(authRequestBuilder: AuthRequestBuilderProtocol) {
21+
self.type = 1
22+
self.authRequestBuilder = authRequestBuilder
23+
}
24+
25+
public init(secret: String) {
26+
self.type = 2
27+
self.secret = secret
28+
}
29+
30+
public init(authorizer: Authorizer) {
31+
self.type = 3
32+
self.authorizer = authorizer
33+
}
34+
}

Sources/ObjC/OCPusherHost.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
@objcMembers
4+
@objc public class OCPusherHost: NSObject {
5+
var type: Int
6+
var host: String?
7+
var cluster: String?
8+
9+
override public init() {
10+
self.type = 2
11+
}
12+
13+
public init(host: String) {
14+
self.type = 0
15+
self.host = host
16+
}
17+
18+
public init(cluster: String) {
19+
self.type = 1
20+
self.cluster = cluster
21+
}
22+
}

Sources/ObjC/ObjectiveC.swift

Lines changed: 0 additions & 229 deletions
This file was deleted.

Sources/ObjC/Pusher+ObjectiveC.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Foundation
2+
3+
@objc public extension Pusher {
4+
func subscribe(channelName: String) -> PusherChannel {
5+
return self.subscribe(channelName, onMemberAdded: nil, onMemberRemoved: nil)
6+
}
7+
8+
func subscribe(
9+
channelName: String,
10+
onMemberAdded: ((PusherPresenceChannelMember) -> Void)? = nil,
11+
onMemberRemoved: ((PusherPresenceChannelMember) -> Void)? = nil
12+
) -> PusherChannel {
13+
return self.subscribe(channelName, auth: nil, onMemberAdded: onMemberAdded, onMemberRemoved: onMemberRemoved)
14+
}
15+
16+
func subscribeToPresenceChannel(channelName: String) -> PusherPresenceChannel {
17+
return self.subscribeToPresenceChannel(channelName: channelName,
18+
auth: nil,
19+
onMemberAdded: nil,
20+
onMemberRemoved: nil)
21+
}
22+
23+
func subscribeToPresenceChannel(
24+
channelName: String,
25+
onMemberAdded: ((PusherPresenceChannelMember) -> Void)? = nil,
26+
onMemberRemoved: ((PusherPresenceChannelMember) -> Void)? = nil
27+
) -> PusherPresenceChannel {
28+
return self.subscribeToPresenceChannel(channelName: channelName,
29+
auth: nil,
30+
onMemberAdded: onMemberAdded,
31+
onMemberRemoved: onMemberRemoved)
32+
}
33+
34+
convenience init(withAppKey key: String, options: PusherClientOptions) {
35+
self.init(key: key, options: options)
36+
}
37+
38+
convenience init(withKey key: String) {
39+
self.init(key: key)
40+
}
41+
}

0 commit comments

Comments
 (0)