SwiftData: reset cache

If reseting the scheme in CloudKit Console does not do the trick or you encounter errors, try deleting the locally cached database:

guard let dir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).last else {
  print("no url")
  return
}

let url = dir.appendingPathComponent("default.store")

if FileManager.default.fileExists(atPath: url.path) {
  print("swiftdata db at \(url.absoluteString)")
  do {
    try FileManager.default.removeItem(at: url)
  } catch {
    print("could not remove db")
  }
}

Subscribe to pwny.ninja

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe