mcpField
S
swift-networking

swift-networking

github.com/johnrogersDevelopment233159 installsUpdated 40w ago
Repository

About swift-networking

A networking skill for Swift developers using Apple's Network.framework. It guides TCP, UDP, and QUIC connection setup, lifecycle handling, migration, and troubleshooting.

Key features

  1. 01Choosing TCP, UDP, or QUIC
  2. 02NWConnection setup and lifecycle
  3. 03NetworkConnection async/await guidance
  4. 04Sending and receiving with error handling
  5. 05Network transition and retry guidance

Use cases

  1. 01Building custom-protocol or UDP networking
  2. 02Managing connection state and failures
  3. 03Migrating from sockets or URLSession
  4. 04Troubleshooting timeouts and TLS failures

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/johnrogers/claude-swift-engineering --skill swift-networking

After installing, type/swift-networkingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
connection-states.md
getting-started.md
ios26-networking.md
migration.md
troubleshooting.md

Details

From the project README

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.

ReferenceLoad When
Getting StartedSetting up NWConnection for TCP/UDP, choosing between APIs
Connection StatesHandling .waiting, .ready, .failed transitions
iOS 26+ NetworkingUsing NetworkConnection with async/await, TLV framing, Coder protocol
Migration GuideMoving from sockets, CFSocket, SCNetworkReachability, URLSession
TroubleshootingDebugging timeouts, TLS failures, connection issues

Core Workflow

  1. Choose transport (TCP/UDP/QUIC) based on use case
  2. Create NWConnection (iOS 12+) or NetworkConnection (iOS 26+)
  3. Set up state handler for connection lifecycle
  4. Start connection on appropriate queue
  5. Send/receive data with proper error handling
  6. 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

  1. 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.

  2. Blocking the main thread — Never call receive() on the main queue. Use a background DispatchQueue or Task for all network operations.

  3. 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.

  4. Not handling network transitions — WiFi/cellular switches or network loss aren't always detected automatically. Implement viability checks and state monitoring for robust apps.

  5. Improper error recovery — Network errors need retry logic with backoff. Immediately failing on transient errors (timeouts, temporary loss) creates poor UX.

Comments

Markdown supported