Introduction
Until now, iOS developers who wanted real‑time, bi‑directional communication with SignalR had to rely on community‑built clients or roll their own Swift implementation—both of which introduced maintenance and compatibility headaches. We’re excited to announce that the official SignalR Swift client is now available in public preview.
With this release, you can:
- Quickly add real‑time features (chat, notifications, live dashboards) to your SwiftUI or UIKit apps.
- Leverage full SignalR functionality—hubs, groups, client/server streaming—on iOS and macOS.
- Rely on an officially supported, maintained, and tested library.
In this post you’ll learn how to set up the Swift client and use its core features. During a recent .NET Community Standup, we demoed an AI-enabled chat sample that uses SignalR for streaming AI‑generated tokens to iOS clients. We recommend you having a watch. You can find the repo referenced in the episode at the end of this blog post.
How to set up Swift client and use its core features
Requirements
- Swift >= 5.10
- macOS >= 11.0
- iOS >= 14
Install via Swift Package Manager
Add the SignalR Swift package as a dependency in your Package.swift
file:
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "signalr-client-app",
dependencies: [
.package(url: "https://github.com/dotnet/signalr-client-swift", branch: "main")
],
targets: [
.executableTarget(name: "YourTargetName", dependencies: [.product(name: "SignalRClient", package: "signalr-client-swift")])
]
)
After adding the dependency, import the library in your Swift code:
Establish a Hub Connection
Create and start your connection:
let connection = HubConnectionBuilder()
.withUrl(url: "https://your-signalr-server/hub")
.build()
try await connection.start()
Tip: Register your handlers before calling start()
to avoid missing early messages.
After adding the dependency, import the library in your Swift code:
import SignalRClient
Receive Server Calls
To handle messages from the server, use on
:
await connection.on("ReceiveMessage") { (user: String, msg: String) in
print("(user): (msg)") }
On your .NET hub:
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message) =>
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
The method name and parameters must match exactly.
The post Building Real‑Time iOS Apps with SignalR: Introducing the Official Swift Client (Public Preview) appeared first on .NET Blog.