HTTP Client Lifetime (ARCH9083)
هذا المحتوى غير متوفر بلغتك بعد.
Key swift.performance.http-client-lifetime · Severity error · Category performance
Flags URLSession(configuration:) created inside a function body - each call rebuilds the connection pool.
Incorrect
Section titled “Incorrect”func fetch(_ url: URL) async throws -> Data { let session = URLSession(configuration: .default) return try await session.data(from: url).0}Correct
Section titled “Correct”private let session = URLSession(configuration: .default)func fetch(_ url: URL) async throws -> Data { try await session.data(from: url).0 }Create the session once and reuse it (or use URLSession.shared).