Agent skill
swift-networking
Use when implementing Network.framework connections (NWConnection, NetworkConnection), debugging connection failures, migrating from sockets/URLSession streams, or handling network transitions. Covers UDP/TCP patterns, structured concurrency networking (iOS 26+), and common anti-patterns.
Install this agent skill to your Project
npx add-skill https://github.com/johnrogers/claude-swift-engineering/tree/main/plugins/swift-engineering/skills/swift-networking
SKILL.md
Swift Networking
Network.framework is Apple's modern networking API for TCP/UDP connections, replacing BSD sockets with smart connection establishment, user-space networking, and seamless mobility handling.
Reference Loading Guide
ALWAYS load reference files if there is even a small chance the content may be required. It's better to have the context than to miss a pattern or make a mistake.
| Reference | Load When |
|---|---|
| Getting Started | Setting up NWConnection for TCP/UDP, choosing between APIs |
| Connection States | Handling .waiting, .ready, .failed transitions |
| iOS 26+ Networking | Using NetworkConnection with async/await, TLV framing, Coder protocol |
| Migration Guide | Moving from sockets, CFSocket, SCNetworkReachability, URLSession |
| Troubleshooting | Debugging timeouts, TLS failures, connection issues |
Core Workflow
- Choose transport (TCP/UDP/QUIC) based on use case
- Create NWConnection (iOS 12+) or NetworkConnection (iOS 26+)
- Set up state handler for connection lifecycle
- Start connection on appropriate queue
- Send/receive data with proper error handling
- Handle network transitions (WiFi to cellular)
When to Use Network.framework vs URLSession
- URLSession: HTTP, HTTPS, WebSocket, simple TCP/TLS streams
- Network.framework: UDP, custom protocols, low-level control, peer-to-peer, gaming
Common Mistakes
-
Ignoring state handlers — Creating an NWConnection without a state change handler means you never learn when it's ready or failed. Always implement the state handler first.
-
Blocking the main thread — Never call
receive()on the main queue. Use a background DispatchQueue or Task for all network operations. -
Wrong queue selection — Using the wrong queue (UI queue for network work, or serial queue for concurrent reads) causes deadlocks or silent failures. Always explicit your queue choice.
-
Not handling network transitions — WiFi/cellular switches or network loss aren't always detected automatically. Implement viability checks and state monitoring for robust apps.
-
Improper error recovery — Network errors need retry logic with backoff. Immediately failing on transient errors (timeouts, temporary loss) creates poor UX.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
swiftui-advanced
Use when implementing gesture composition (simultaneous, sequenced, exclusive), adaptive layouts (ViewThatFits, AnyLayout, size classes), or choosing architecture patterns (MVVM vs TCA vs vanilla, State-as-Bridge). Covers advanced SwiftUI patterns beyond basic views.
ios-hig
Use when designing iOS interfaces, implementing accessibility (VoiceOver, Dynamic Type), handling dark mode, ensuring adequate touch targets, providing animation/haptic feedback, or requesting user permissions. Apple Human Interface Guidelines for iOS compliance.
ios-26-platform
Use when implementing iOS 26 features (Liquid Glass, new SwiftUI APIs, WebView, Chart3D), deploying iOS 26+ apps, or supporting backward compatibility with iOS 17/18.
swiftui-patterns
Use when implementing iOS 17+ SwiftUI patterns: @Observable/@Bindable, MVVM architecture, NavigationStack, lazy loading, UIKit interop, accessibility (VoiceOver/Dynamic Type), async operations (.task/.refreshable), or migrating from ObservableObject/@StateObject.
grdb
Use when writing raw SQL with GRDB, complex joins across 4+ tables, window functions, ValueObservation for reactive queries, or dropping down from SQLiteData for performance. Direct SQLite access for iOS/macOS with type-safe queries and migrations.
swift-testing
Use when writing tests with Swift Testing (@Test,
Didn't find tool you were looking for?