Browse Questions
  • These four declarations differ in two dimensions: whether the array itself is optional, and whether the elements inside are optional.
  • Use separate Xcode Schemes, Build Configurations, Bundle Identifiers, and Firebase plists — one set per environment.
  • Result<Success, Failure> is an enum with .success and .failure cases.
  • Delegation is a pattern where one object hands off responsibility to another through a protocol, letting a child communicate back to its owner without knowing its concrete type.

Answer: Result<Success, Failure> is an enum with .success and .failure cases. It makes error handling explicit and is ideal for async operations, replacing optional + error patterns.

Code Example:

enum NetworkError: Error {
    case badURL
    case noData
    case decodingFailed
}

func fetchUser(id: Int, completion: @escaping (Result<User, NetworkError>) -> Void) {
    guard let url = URL(string: "https://api.example.com/users/\(id)") else {
        completion(.failure(.badURL))
        return
    }
    // ... network call
    completion(.success(user))
}

// Usage
fetchUser(id: 1) { result in
    switch result {
    case .success(let user):
        print("Got user: \(user.name)")
    case .failure(let error):
        print("Error: \(error)")
    }
}