kean / Pulse

Network logger for Apple platforms
https://pulselogger.com
MIT License
6.18k stars 294 forks source link

Xcode 15.3 reports that Pulse is performing I/O on the main thread, which can lead to app hangs #245

Open Taeeun-Kim opened 5 months ago

Taeeun-Kim commented 5 months ago

Xcode version: 15.3 Pulse version: 4.0.5

Error:

{"message":"This code path does I/O on the main thread underneath that can lead to UI responsiveness issues. Consider ways to optimize this code path","antipattern trigger":"-[NSData initWithContentsOfURL:options:error:]","message type":"suppressable","show in console":"0"}

Code:

extension LoggerStore {
    private struct Manifest: Codable {
        var storeId: UUID
        var version: Version
        var lastSweepDate: Date?

        init(storeId: UUID, version: Version) {
            self.storeId = storeId
            self.version = version
        }

        init?(url: URL) {
            guard let data = try? Data(contentsOf: url),
                  let manifest = try? JSONDecoder().decode(Manifest.self, from: data) else {
                return nil
            }
            self = manifest
        }
    }
}

image