🧱

Foundation

iOS 2+

The fundamental framework providing essential data types, collections, and operating system services. Foundation is the base layer for all iOS apps, offering classes for strings, arrays, dates, and more.

Core
Official Apple Documentation →
iOS Version Compatibility
99.8%
coverage

of iOS users worldwide can use Foundation (iOS 2+ required)

iOS VersionMarket ShareStatus
iOS 18.730.3%Supported
iOS 18.629.8%Supported
iOS 26.110.7%Supported
iOS 18.56.0%Supported
iOS 16.72.3%Supported
iOS 26.22.0%Supported
iOS 18.31.8%Supported
iOS 15.81.8%Supported
iOS 11.01.7%Supported
iOS 17.61.7%Supported

Key Features

Essential data types (String, Array, Dictionary)

Date and time handling

File system access and bundle management

URL handling and networking primitives

JSON encoding and decoding

User defaults and preferences

Code Examples

Working with Arrays and Dictionaries

Use Foundation collection types

import Foundation

// Arrays
var numbers = [1, 2, 3, 4, 5]
numbers.append(6)
let doubled = numbers.map { $0 * 2 }

// Dictionaries
var userInfo: [String: Any] = [
    "name": "John Doe",
    "age": 30,
    "email": "john@example.com"
]

if let name = userInfo["name"] as? String {
    print("User: \(name)")
}

JSON Encoding and Decoding

Work with JSON data using Codable

import Foundation

struct User: Codable {
    let id: Int
    let name: String
    let email: String
}

// Encoding
let user = User(id: 1, name: "John", email: "john@example.com")
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted

if let jsonData = try? encoder.encode(user),
   let jsonString = String(data: jsonData, encoding: .utf8) {
    print(jsonString)
}

// Decoding
let jsonString = """
{"id": 1, "name": "John", "email": "john@example.com"}
"""
if let jsonData = jsonString.data(using: .utf8),
   let decoded = try? JSONDecoder().decode(User.self, from: jsonData) {
    print(decoded.name)
}

Working with Dates

Date manipulation and formatting

import Foundation

// Current date
let now = Date()

// Date formatting
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
let dateString = formatter.string(from: now)
print(dateString) // "Dec 3, 2025 at 2:30 PM"

// Date arithmetic
let calendar = Calendar.current
if let tomorrow = calendar.date(byAdding: .day, value: 1, to: now) {
    print("Tomorrow: \(tomorrow)")
}

// Date comparison
let futureDate = Date().addingTimeInterval(3600)
if futureDate > now {
    print("futureDate is later")
}

Frequently Asked Questions

What is Foundation?

The fundamental framework providing essential data types, collections, and operating system services. Foundation is the base layer for all iOS apps, offering classes for strings, arrays, dates, and more.

Which iOS versions support Foundation?

Foundation is available on iOS 2 and later. Currently, 99.8% of iOS users worldwide can use this framework.

What are alternatives to Foundation?

Related frameworks include Uikit, Swiftui. Each has different capabilities and iOS version requirements.