Skip to content

Commit 89e63d4

Browse files
Fix code snippet in README
Specify channel modes, and attach the channel (we will shortly be introducing an implicit attach on getRoot but we don't have it yet).
1 parent 010b3e0 commit 89e63d4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,23 @@ clientOptions.plugins = [.liveObjects: AblyLiveObjects.Plugin.self]
2525

2626
let realtime = ARTRealtime(options: clientOptions)
2727

28-
// You can now access LiveObjects functionality via a channel's `objects` property:
29-
let channel = realtime.channels.get("myChannel")
28+
// Fetch a channel, specifying the `.objectPublish` and `.objectSubscribe` modes
29+
let channelOptions = ARTRealtimeChannelOptions()
30+
channelOptions.modes = [.objectPublish, .objectSubscribe]
31+
let channel = realtime.channels.get("myChannel", options: channelOptions)
32+
33+
// Attach the channel
34+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
35+
channel.attach { error in
36+
if let error {
37+
continuation.resume(throwing: error)
38+
} else {
39+
continuation.resume()
40+
}
41+
}
42+
}
43+
44+
// You can now access LiveObjects functionality via the channel's `objects` property:
3045
let rootObject = try await channel.objects.getRoot()
3146
// …and so on
3247
```

Sources/AblyLiveObjects/Public/Plugin.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,23 @@ import ObjectiveC.NSObject
1515
///
1616
/// let realtime = ARTRealtime(options: clientOptions)
1717
///
18-
/// // You can now access LiveObjects functionality via a channel's `objects` property:
19-
/// let channel = realtime.channels.get("myChannel")
18+
/// // Fetch a channel, specifying the `.objectPublish` and `.objectSubscribe` modes
19+
/// let channelOptions = ARTRealtimeChannelOptions()
20+
/// channelOptions.modes = [.objectPublish, .objectSubscribe]
21+
/// let channel = realtime.channels.get("myChannel", options: channelOptions)
22+
///
23+
/// // Attach the channel
24+
/// try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
25+
/// channel.attach { error in
26+
/// if let error {
27+
/// continuation.resume(throwing: error)
28+
/// } else {
29+
/// continuation.resume()
30+
/// }
31+
/// }
32+
/// }
33+
///
34+
/// // You can now access LiveObjects functionality via the channel's `objects` property:
2035
/// let rootObject = try await channel.objects.getRoot()
2136
/// // …and so on
2237
/// ```

0 commit comments

Comments
 (0)