Browse Questions
  • OSLog is Apple's structured logging framework.
  • FlowLayout uses the Layout protocol (iOS 16+) — SwiftUI's official first-party layout system.
  • ARC is Swift's compile-time memory management system that automatically inserts retain and release calls to allocate and free class instances on the heap.
  • URLSession is Apple's networking API for HTTP requests.

Answer: OSLog is Apple's structured logging framework. It's faster than print, integrates with Console.app, supports log levels, and redacts sensitive data in production.

Code Example:

import OSLog

// Create a logger with subsystem and category
private let logger = Logger(subsystem: "com.myapp", category: "networking")

class NetworkManager {
    func fetchUser(id: Int) async throws -> User {
        logger.info("Fetching user \(id)")

        do {
            let user = try await api.getUser(id: id)
            logger.debug("User fetched: \(user.name)")
            return user
        } catch {
            logger.error("Failed to fetch user: \(error.localizedDescription)")
            throw error
        }
    }
}

Log levels:

  • .debug — verbose, only in development
  • .info — general info, retained briefly
  • .notice — important events
  • .error — recoverable errors
  • .fault — serious bugs, always persisted

Why better than print:

  • Compiled out of release builds (.debug)
  • Auto-redacts private data: logger.info("Token: \(token, privacy: .private)")
  • Viewable in Console.app on device without Xcode
  • Negligible performance impact