iOS Development iOS Networking and APIs 2 — Questions and Answers
Question 1: What is certificate pinning in iOS networking?
- Validating a server's certificate against a known copy bundled in the app (Correct answer)
- Requiring a PIN code before making requests
- Limiting requests to pinned IP addresses
- Caching TLS handshake results
Correct answer: Validating a server's certificate against a known copy bundled in the app
Certificate pinning prevents man-in-the-middle attacks by comparing the server's certificate to a trusted copy embedded in the app bundle.
Question 2: What does an HTTP 401 status code mean?
- Unauthorized — the request requires valid authentication (Correct answer)
- Forbidden — access is denied regardless of credentials
- Not Found — the resource doesn't exist
- Bad Request — the request was malformed
Correct answer: Unauthorized — the request requires valid authentication
HTTP 401 Unauthorized means the request lacks valid authentication credentials and the client should authenticate before retrying.
Question 3: Which URLSession configuration runs tasks even when the app is suspended?
- background (Correct answer)
- default
- ephemeral
- shared
Correct answer: background
A background URLSession configuration allows downloads and uploads to continue after the app moves to the background or is suspended.
Question 4: What is the Combine framework's role in iOS networking?
- Provides a reactive, publisher-based API for processing asynchronous events like network responses (Correct answer)
- Replaces URLSession for all HTTP requests
- Manages SSL certificates for secure connections
- Handles DNS resolution
Correct answer: Provides a reactive, publisher-based API for processing asynchronous events like network responses
Combine lets you chain URLSession responses as publishers, applying operators like `map`, `decode`, and `catch` in a reactive pipeline.
Question 5: What is a REST API in iOS development context?
- An HTTP-based API that uses standard methods (GET/POST/PUT/DELETE) and stateless requests (Correct answer)
- A binary protocol for low-latency communication
- A local API for accessing device sensors
- A push notification delivery system
Correct answer: An HTTP-based API that uses standard methods (GET/POST/PUT/DELETE) and stateless requests
REST APIs use standard HTTP methods and stateless request/response cycles, making them the most common backend communication pattern in iOS apps.
Question 6: What does Codable's `CodingKeys` enum allow you to do?
- Map between JSON key names and Swift property names (Correct answer)
- Define the order in which properties are encoded
- Skip encoding properties marked as optional
- Specify custom encoding formats for dates
Correct answer: Map between JSON key names and Swift property names
`CodingKeys` is a nested enum conforming to `CodingKey` that lets you map JSON keys with different names to your Swift struct's property names.
What is certificate pinning in iOS networking?