1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[iOS17] Precondition failed: Incorrect actor executor assumption; Expected 'UnownedSerialExecutor(executor: (Opaque Value))' executor.

Last updated at Posted at 2023-10-19

現象

Realmを使ってCRUD処理をasync/awaitで非同期処理しようと思い、対応させてたら以下のエラーが起きた
Precondition failed: Incorrect actor executor assumption; Expected 'UnownedSerialExecutor(executor: (Opaque Value))' executor.
※iOS17だと上記のエラーが出たがiOS16代は、エラーが発生しなかった。

解決方法

@MainActorの付け忘れだった。

通常は、UIの更新はメインスレッドで行うのが決まりなのに、別スレッドで更新してしまったっぽい。
ただ、私の場合は、とある場所の@MainActorを付け忘れていた部分がありました。

それは、以下の部分でした。(実例)

Model.swift
class Monday: Object, Weekday {
    // MARK: - Property Wrappers
    @Persisted(primaryKey: true) private(set) var _id: ObjectId
    @Persisted var scheduleList = List<String>()
    @Persisted var trainTime: Date?
}

extension Monday: ObjectKeyIdentifiable {}
Weekday.swift
@MainActor
protocol WeekDay where Self: Object {
    // MARK: - Properties
    var _id: ObjectId { get }
    var scheduleList: List<String> { get set }
    var trainTime: Date? { get set }
}

extension WeekDay {
// 以下に関数を宣言して関数内で`scheduleList`と`trainTime`に代入などをして使っていました。

まとめ

このように@MainActorを付与しなければならない場所がまだありました!

悪魔で今回は一例なので、コード見直して先程のアトリビュートの付与忘れを疑ってみてください!

以下の記事にもiOS17で起こると書かれていました

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?