jordancoin/ios-skills-collection/dpearson2699-ios-networking
Claude Code and agent skill by jordancoin/ios-skills-collection
- community
- ext:[{"type":"config","description":"Configuration overrides"}]
Checking that the SKILL.md file is still in the repository.
Build, review, or improve networking code in iOS/macOS apps using URLSession with async/await, structured concurrency, and modern Swift patterns. Use when working with REST APIs, downloading files, uploading data, WebSocket connections, pagination, retry logic, request middleware, caching, background transfers, or network reachability monitoring. Also use when handling HTTP requests, API clients, network error handling, or data fetching in Swift apps.
Install
npx vskill@latest install jordancoin/ios-skills-collection/dpearson2699-ios-networkingSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
iOS Networking
Modern networking patterns for iOS 26+ using URLSession with async/await and structured concurrency. All examples target Swift 6.3. No third-party dependencies required -- URLSession covers the vast majority of networking needs.
Contents
- Core URLSession async/await
- API Client Architecture
- Error Handling
- Pagination
- Network Reachability
- Configuring URLSession
- Common Mistakes
- Review Checklist
- References
Core URLSession async/await
URLSession gained native async/await overloads in iOS 15. These are the only networking APIs to use in new code. Never use completion-handler variants in new projects.
Data Requests
Response Validation
Always validate the HTTP status code before decoding. URLSession does not throw for 4xx/5xx responses -- it only throws for transport-level failures.
JSON Decoding with Codable
Downloads and Uploads
Use download(for:) for large files -- it streams to disk instead of loading the entire payload into memory.
Streaming with AsyncBytes
Use bytes(for:) for streaming responses, progress tracking, or line-delimited data (e.g., server-sent events).
API Client Architecture
Protocol-Based Client
Define a protocol for testability. This lets you swap implementations in tests without mocking URLSession directly.
The client accepts a baseURL, optional custom URLSession, JSONDecoder, and an array of RequestMiddleware interceptors. Each method builds a URLRequest from the endpoint, applies middleware, executes the request, validates the status code, and decodes the result. See references/urlsession-patterns.md for the complete APIClient implementation with convenience methods, request builder, and test setup.
Lightweight Closure-Based Client
For apps using the MV pattern, use closure-based clients for testability and SwiftUI preview support. See references/lightweight-clients.md for the full pattern (struct of async closures, injected via init).
Request Middleware / Interceptors
Middleware transforms requests before they are sent. Use this for authentication, logging, analytics headers, and similar cross-cutting concerns.
Token Refresh Flow
Handle 401 responses by refreshing the token and retrying once.
Error Handling
Structured Error Types
Key URLError Cases
| URLError Code | Meaning | Action | |
|---|---|---|---|
.notConnectedToInternet | Device offline | Show offline UI, queue for retry | |
.networkConnectionLost | Connection dropped mid-request | Retry with backoff | |
.timedOut | Server did not respond in time | Retry once, then show error | |
.cancelled | Task was cancelled | No action needed; do not show error | |
.cannotFindHost | DNS failure | Check URL, show error | |
.secureConnectionFailed | TLS handshake failed | Check cert pinning, ATS config | |
.userAuthenticationRequired | 401 from proxy | Trigger auth flow |
Decoding Server Error Bodies
Retry with Exponential Backoff
Use structured concurrency for retries. Respect task cancellation between attempts. Skip retries for cancellation and 4xx client errors (except 429).
Pagination
Build cursor-based or offset-based pagination with AsyncSequence. Always check Task.isCancelled between pages. See references/urlsession-patterns.md for complete CursorPaginator and offset-based implementations.
Network Reachability
Use NWPathMonitor from the Network framework — not third-party Reachability libraries. Wrap in AsyncStream for structured concurrency.
Check path.isExpensive (cellular) and path.isConstrained (Low Data Mode) to adapt behavior (reduce image quality, skip prefetching).
Configuring URLSession
Create a configured session for production code. URLSession.shared is acceptable only for simple, one-off requests.
waitsForConnectivity = true is valuable -- it makes the session wait for a network path instead of failing immediately when offline. Combine with urlSession(_:taskIsWaitingForConnectivity:) delegate callback for UI feedback.
Common Mistakes
DON'T: Use URLSession.shared with custom configuration needs. DO: Create a configured URLSession with appropriate timeouts, caching, and delegate for production code.
DON'T: Force-unwrap URL(string:) with dynamic input. DO: Use URL(string:) with proper error handling. Force-unwrap is acceptable only for compile-time-constant strings.
DON'T: Decode JSON on the main thread for large payloads. DO: Keep decoding on the calling context of the URLSession call, which is off-main by default. Only hop to @MainActor to update UI state.
DON'T: Ignore cancellation in long-running network tasks. DO: Check Task.isCancelled or call try Task.checkCancellation() in loops (pagination, streaming, retry). Use .task in SwiftUI for automatic cancellation.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/dpearson2699--ios-networking/SKILL.md
Popularity
- Repository stars
- 6
- 7-day trend score
- 10
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
configConfiguration overrides
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jordancoin/ios-skills-collection/dpearson2699-ios-networking)