DevPrep

All topics › Programming basics

API

Junior

Essence

An API (Application Programming Interface) is a contract between two pieces of code: a set of types, functions and rules that one side publishes and the other uses without knowing the internal implementation. The implementation may change as long as the contract holds.

The APIs an iOS developer meets

What a good API looks like in Swift

import Foundation

// The contract: what the service can do. How — is hidden.
public protocol ImageLoading: Sendable {
    func data(for url: URL) async throws -> Data
}

public struct ImageLoader: ImageLoading {
    public init() {}

    public func data(for url: URL) async throws -> Data {
        let (data, _) = try await URLSession.shared.data(from: url)
        return data
    }

    private func cacheKey(for url: URL) -> String {   // not part of the API
        url.absoluteString
    }
}

@available(iOS 26, *)
public func liquidGlassEffect() {}   // availability is part of the contract too

API vs framework vs SDK

What the interviewer looks for

Do you understand that changing a public API is a breaking change for every consumer, and that inside an app module boundaries should also be designed as APIs: through protocols and minimal visibility.

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store