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.
of iOS users worldwide can use Foundation (iOS 2+ required)
| iOS Version | Market Share | Status |
|---|---|---|
| iOS 18.7 | 30.3% | Supported |
| iOS 18.6 | 29.8% | Supported |
| iOS 26.1 | 10.7% | Supported |
| iOS 18.5 | 6.0% | Supported |
| iOS 16.7 | 2.3% | Supported |
| iOS 26.2 | 2.0% | Supported |
| iOS 18.3 | 1.8% | Supported |
| iOS 15.8 | 1.8% | Supported |
| iOS 11.0 | 1.7% | Supported |
| iOS 17.6 | 1.7% | Supported |
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
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)")
}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)
}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")
}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.
Foundation is available on iOS 2 and later. Currently, 99.8% of iOS users worldwide can use this framework.
Related frameworks include Uikit, Swiftui. Each has different capabilities and iOS version requirements.