I have the feeling I do not understand something or it is a compiler bug.
I have 2 instances like in this code snippet:
public enum ItemKind: CaseIterable, Hashable, Sendable {
case header
case cell
case footer
init(_ elementKind: String) {
switch elementKind {
case UICollectionView.elementKindSectionHeader:
self = .header
case UICollectionView.elementKindSectionFooter:
self = .footer
default:
preconditionFailure("Unsupported supplementary view kind.")
}
}
// @MainActor
var supplementaryElementStringType: String {
switch self {
case .cell:
preconditionFailure("Cell type is not a supplementary view.")
case .header:
UICollectionView.elementKindSectionHeader
case .footer:
UICollectionView.elementKindSectionFooter
}
}
}
enum ChangeItem: Equatable, Sendable {
//@MainActor
init?(with updateItem: UICollectionViewUpdateItem) {
print(updateItem.indexPathAfterUpdate ?? "nil")
return nil
}
}
Compiler requires @MainActor in constructor for the ChangeItem
but not for ItemKind
. I do not understand why. Id expect ItemKind
constructor also should require @MainActor