@@ -17,6 +17,8 @@ Everything you need to get started with Ably:
1717- [ Getting started with Ably Chat using Swift.] ( https://ably.com/docs/chat/getting-started/swift )
1818- [ Ably Chat SDK and usage docs in Swift.] ( https://ably.com/docs/chat/setup?lang=swift )
1919- Learn [ about Ably Chat.] ( https://ably.com/docs/chat )
20+ - [ API documentation.] ( https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/ )
21+ - [ Chat Example App.] ( https://github.com/ably/ably-chat-swift/tree/main/Example )
2022- Play with the [ livestream chat demo.] ( https://ably-livestream-chat-demo.vercel.app/ )
2123
2224---
@@ -38,6 +40,77 @@ This SDK supports the following platforms:
3840
3941---
4042
43+ ## Installation
44+
45+ The SDK is distributed as a Swift Package and can be installed using Xcode or by adding it as a dependency in your package's ` Package.swift ` .
46+
47+ #### Using Xcode
48+
49+ To install the ` ably-chat-swift ` package in your Xcode Project:
50+
51+ 1 . Open your Xcode project and navigate to ** File → Add Package Dependencies...**
52+ 2 . Paste ` https://github.com/ably/ably-chat-swift ` in the search box
53+ 3 . Select the version you want to use
54+ 4 . Select the Ably Chat SDK for your target
55+
56+ #### Using Swift Package Manager
57+
58+ To install the ` ably-chat-swift ` package in another Swift Package, add the following to your ` Package.swift ` :
59+
60+ ``` swift
61+ .package (url : " https://github.com/ably/ably-chat-swift" , from : " 1.1.0" ),
62+ ```
63+
64+ ---
65+
66+ ## Usage
67+
68+ The following code connects to Ably's chat service, subscribes to a chat room, and sends a message to that room:
69+
70+ ``` swift
71+ import Ably
72+ import AblyChat
73+
74+ // Initialize Ably Realtime client
75+ let realtimeOptions = ARTClientOptions ()
76+ realtimeOptions.key = " <your-ably-api-key>"
77+ realtimeOptions.clientId = " your-client-id"
78+ let realtime = ARTRealtime (options : realtimeOptions)
79+
80+ // Create a chat client
81+ let chatClient = ChatClient (realtime : realtime, clientOptions : ChatClientOptions ())
82+
83+ // Get a chat room
84+ let room = try await chatClient.rooms .get (named : " my-room" , options : RoomOptions ())
85+
86+ // Monitor room status
87+ room.onStatusChange { statusChange in
88+ switch statusChange.current {
89+ case .attached :
90+ print (" Room is attached" )
91+ case .detached :
92+ print (" Room is detached" )
93+ case .failed (let error):
94+ print (" Room failed: \( error ) " )
95+ default :
96+ print (" Room status: \( statusChange.current ) " )
97+ }
98+ }
99+
100+ // Attach to the room
101+ try await room.attach ()
102+
103+ // Subscribe to messages
104+ let subscription = room.messages .subscribe { event in
105+ print (" Received message: \( event.message .text ) " )
106+ }
107+
108+ // Send a message
109+ try await room.messages .send (withParams : SendMessageParams (text : " Hello, World!" ))
110+ ```
111+
112+ ---
113+
41114## Releases
42115
43116The [ CHANGELOG.md] ( /CHANGELOG.md ) contains details of the latest releases for this SDK. You can also view all Ably releases on [ changelog.ably.com] ( https://changelog.ably.com ) .
0 commit comments