Skip to content

Commit f801ec1

Browse files
Offload Image loading from main thread
1 parent ba03b37 commit f801ec1

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Demo/PowerSyncExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/PowerSyncExample/Components/TodoListRow.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ struct TodoListRow: View {
2323
// Show progress while loading the image
2424
ProgressView()
2525
.onAppear {
26-
loadImage()
26+
Task {
27+
await loadImage()
28+
}
2729
}
2830
} else if todo.photoId != nil {
2931
// Show progres, wait for a URI to be present
@@ -75,15 +77,19 @@ struct TodoListRow: View {
7577
}
7678
}
7779

78-
private func loadImage() {
79-
guard let urlString = todo.photoUri else {
80-
return
81-
}
80+
private func loadImage() async {
81+
guard let urlString = todo.photoUri else { return }
82+
let url = URL(fileURLWithPath: urlString)
8283

83-
if let imageData = try? Data(contentsOf: URL(fileURLWithPath: urlString)),
84-
let loadedImage = UIImage(data: imageData)
85-
{
86-
image = loadedImage
84+
do {
85+
let data = try Data(contentsOf: url)
86+
if let loadedImage = UIImage(data: data) {
87+
image = loadedImage
88+
} else {
89+
print("Failed to decode image from data.")
90+
}
91+
} catch {
92+
print("Error loading image from disk:", error)
8793
}
8894
}
8995
}

Demo/PowerSyncExample/PowerSync/SystemManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class SystemManager {
127127
sql: "SELECT photo_id FROM \(TODOS_TABLE) WHERE list_id = ? AND photo_id IS NOT NULL",
128128
parameters: [id]
129129
) { cursor in
130-
cursor.getString(index: 0)! // :(
130+
// FIXME Transactions should allow throwing in the mapper and should use generics correctly
131+
cursor.getString(index: 0) ?? "invalid" // :(
131132
} as? [String] // :(
132133

133134
_ = try transaction.execute(

0 commit comments

Comments
 (0)