TwitchChat is a Swift library for consuming chat from Twitch streams.
The only supported method of installation for TwitchChat is Apple’s Swift Package Manager. To add TwitchChat to an Xcode project, follow Apple’s tutorial on adding package dependencies to your app. The URL to use for installation is the GitHub repo for TwitchChat: https://github.com/cocoatype/twitch-chat.
When adding TwitchChat as a package dependency, be sure to check only the TwitchChat library and not the TwitchChatClient example project:
If using TwitchChat as a sub-package of another package, you can add it to your Package.swift file’s dependencies like so:
dependencies: [
.package(url: "https://github.com/cocoatype/twitch-chat", .exactItem("0.0.1"))
]To use TwitchChat, first create an instance of TwitchChat by passing in a user access token and the name of the channel whose chat you want to receive messages for:
let chat = TwitchChat(token: "my-user-token", name: "cocoatype")After creating an instance of TwitchChat, you can receive messages by reading the asynchronous messages property:
for try await message in chat.messages {
// display messages
}A message contains several properties: the sender, the sender’s preferred chat color, the text of the message, and an array of emotes included in the message.
The array of emotes included in each message includes a URL for downloading the image associated with the emote and a range of characters to replace when displaying the emote.
TwitchChatAppKit is an optional package that provides message rendering capabilities in AppKit-based macOS apps. It provides one type, ChatMessageRenderer, which can be used to create attributed strings with included emotes. It can be used like so:
for try await message in chat.messages {
let messageString = await ChatMessageRenderer.attributedString(for: message, font: Self.font)
messageTextField.attributedStringValue = messageString
}TwitchChat is not accepting code contributions at this time. Please feel free to file any issues and bug reports you may come across.
TwitchChat is licensed under the MIT License.