Skip to content

Commit aae8729

Browse files
committed
Change to networkOperation in PostsPageViewController.swift. Previous change allowed for builds without error but failed during TestFlight upload. This version passes TestFlight and also more closely reflects similar networkOperation setup in other files.
1 parent cdb70f4 commit aae8729

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

App/View Controllers/Posts/PostsPageViewController.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ final class PostsPageViewController: ViewController {
4141
@FoilDefaultStorage(Settings.jumpToPostEndOnDoubleTap) private var jumpToPostEndOnDoubleTap
4242
private var jumpToPostIDAfterLoading: String?
4343
private var messageViewController: MessageComposeViewController?
44-
// Stored as Any because Task returns non-Sendable Core Data objects (Post: NSManagedObject).
45-
// Swift 6 requires Task<Success, Failure> Success types to be Sendable.
46-
private var networkOperation: Any?
44+
private var networkOperation: Task<Void, Never>?
4745
private var observers: [NSKeyValueObservation] = []
4846
private lazy var oEmbedFetcher: OEmbedFetcher = .init()
4947
private(set) var page: ThreadPage?
@@ -163,7 +161,10 @@ final class PostsPageViewController: ViewController {
163161
}
164162

165163
deinit {
166-
(networkOperation as? Task<(posts: [Post], firstUnreadPost: Int?, advertisementHTML: String), Error>)?.cancel()
164+
// Avoid warning in Xcode 14 beta 1 "cannot access property with a non-sendable type from a non-isolated deinit"
165+
// UIViewController actually does guarantee deinit on the main queue, but the Swift compiler doesn't know that.
166+
// (Also, it seems like an oversight that wrapping the access in an immediately-executed closure avoids the warning, so be prepared for more warnings here.)
167+
{ networkOperation?.cancel() }()
167168
}
168169

169170
var posts: [Post] = []
@@ -201,8 +202,8 @@ final class PostsPageViewController: ViewController {
201202
) {
202203
flagRequest?.cancel()
203204
flagRequest = nil
204-
(networkOperation as? Task<(posts: [Post], firstUnreadPost: Int?, advertisementHTML: String), Error>)?.cancel()
205-
networkOperation = nil
205+
206+
guard networkOperation == nil else { return }
206207

207208
// prevent white flash caused by webview being opaque during refreshes
208209
if darkMode {
@@ -260,8 +261,9 @@ final class PostsPageViewController: ViewController {
260261
}
261262
return try await ForumsClient.shared.listPosts(in: thread, writtenBy: author, page: newPage, updateLastReadPost: updateLastReadPost)
262263
}
263-
networkOperation = fetch
264-
Task { [weak self] in
264+
265+
networkOperation = Task { @MainActor [weak self] in
266+
defer { self?.networkOperation = nil }
265267
do {
266268
let (posts, firstUnreadPost, _) = try await fetch.value
267269
guard let self else { return }

0 commit comments

Comments
 (0)