Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions App/Composition/SmiliePicker/SmilieSearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,24 @@ final class SmilieSearchViewModel: ObservableObject {

func updateLastUsedDate(for smilie: Smilie) {
guard let context = dataStore.managedObjectContext else { return }
context.perform {
smilie.metadata.lastUsedDate = Date()
do {
try context.save()
} catch {
print("Error saving last used date: \(error)")
let smilieID = smilie.objectID
Task {
await context.perform {
guard let smilie = context.object(with: smilieID) as? Smilie,
let smilieText = smilie.text else { return }

let fetchRequest = NSFetchRequest<Smilie>(entityName: "Smilie")
fetchRequest.predicate = NSPredicate(format: "text == %@", smilieText)
fetchRequest.fetchLimit = 1

do {
if let smilie = try context.fetch(fetchRequest).first {
smilie.metadata.lastUsedDate = Date()
try context.save()
}
} catch {
print("Error saving last used date: \(error)")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion App/Refreshers/AnnouncementListRefresher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright 2017 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app

import AwfulCore
import CoreData
@preconcurrency import CoreData
import os
import UIKit

Expand Down
12 changes: 7 additions & 5 deletions App/View Controllers/Posts/PostsPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//
// Copyright 2016 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app

import AwfulCore
@preconcurrency import AwfulCore
import AwfulModelTypes
import AwfulSettings
import AwfulTheming
import Combine
import CoreData
@preconcurrency import CoreData
import MobileCoreServices
import MRProgress
import os
Expand Down Expand Up @@ -41,7 +41,9 @@ final class PostsPageViewController: ViewController {
@FoilDefaultStorage(Settings.jumpToPostEndOnDoubleTap) private var jumpToPostEndOnDoubleTap
private var jumpToPostIDAfterLoading: String?
private var messageViewController: MessageComposeViewController?
private var networkOperation: Task<(posts: [Post], firstUnreadPost: Int?, advertisementHTML: String), Error>?
// Stored as Any because Task returns non-Sendable Core Data objects (Post: NSManagedObject).
// Swift 6 requires Task<Success, Failure> Success types to be Sendable.
private var networkOperation: Any?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeesh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha!

private var observers: [NSKeyValueObservation] = []
private lazy var oEmbedFetcher: OEmbedFetcher = .init()
private(set) var page: ThreadPage?
Expand Down Expand Up @@ -160,7 +162,7 @@ final class PostsPageViewController: ViewController {
}

deinit {
networkOperation?.cancel()
(networkOperation as? Task<(posts: [Post], firstUnreadPost: Int?, advertisementHTML: String), Error>)?.cancel()
}

var posts: [Post] = []
Expand Down Expand Up @@ -198,7 +200,7 @@ final class PostsPageViewController: ViewController {
) {
flagRequest?.cancel()
flagRequest = nil
networkOperation?.cancel()
(networkOperation as? Task<(posts: [Post], firstUnreadPost: Int?, advertisementHTML: String), Error>)?.cancel()
networkOperation = nil

// prevent white flash caused by webview being opaque during refreshes
Expand Down
2 changes: 1 addition & 1 deletion AwfulCore/Sources/AwfulCore/Model/AwfulManagedObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import CoreData

/// A slightly more convenient NSManagedObject for entities with a custom class.
public class AwfulManagedObject: NSManagedObject {
public class AwfulManagedObject: NSManagedObject, @unchecked Sendable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably ditch this subclass tbh. but ok for now

public var objectKey: AwfulObjectKey {
fatalError("subclass implementation please")
}
Expand Down
2 changes: 1 addition & 1 deletion AwfulCore/Sources/AwfulCore/Model/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CoreData

/// A single reply to a thread.
@objc(Post)
public class Post: AwfulManagedObject, Managed {
public class Post: AwfulManagedObject, Managed, @unchecked Sendable {
public static var entityName: String { "Post" }

/// Whether the logged-in user can edit the post.
Expand Down
1 change: 1 addition & 0 deletions Config/Common.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RUN_CLANG_STATIC_ANALYZER = YES
SDKROOT = iphoneos

SWIFT_EMIT_LOC_STRINGS = YES
SWIFT_STRICT_CONCURRENCY = minimal
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES
SWIFT_VERSION = 5.0

Expand Down
Loading