Browse Questions
  • OSLog is Apple's structured logging framework.
  • Tasks support cooperative cancellation — you cancel from outside, and the task must check for cancellation and stop itself.
  • Inside a ScrollView, SwiftUI's vertical scroll direction makes height unconstrained.
  • Firebase Cloud Messaging (FCM) lets you send push notifications to your iOS app through Apple Push Notification service (APNs).

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