Basic Information
Please provide a descriptive title for your feedback:
PhotosPicker initializer label closure can't call @MainActor methods
Which platform is most relevant for your report?
iOS
Which technology does your report involve?
SwiftUI
What type of feedback are you reporting?
Incorrect/Unexpected Behavior
What build does the issue occur on?
iOS 18 Seed 8 (22A5350a)
Where does the issue occur?
In Xcode
Description
Please describe the issue and what steps we can take to reproduce it:
When using SwiftUI it's fairly common to have view initializers and modifier methods that are annotated with @MainActor, and these cannot be used from the label closure on the PhotosPicker initializer because it's marked as nonisolated.
Example, distilled from the SFSafeSymbols library which is how I actually encountered this, along with an effect modifier from Pow.
- SFSafeSymbols: https://github.com/SFSafeSymbols/SFSafeSymbols
- Pow: https://github.com/EmergeTools/Pow
import PhotosUI
import SwiftUI
enum SFSymbol: String {
case ant
}
extension Label where Title == Text, Icon == Image {
init(_ titleKey: LocalizedStringKey, systemSymbol: SFSymbol) {
self.init(titleKey, systemImage: systemSymbol.rawValue)
}
}
struct ContentView: View {
@State private var item: PhotosPickerItem?
var body: some View {
VStack {
PhotosPicker(selection: $item) {
Label("hello", systemSymbol: .ant)
}
}
}
}
Adding @preconcurrency on the imports has no effect. Should we be declaring these initializers as nonisolated? There's no explicit @MainActor here so it seems like PhotosPicker shouldn't have a @Sendable nonisolated closure for its label, though it does work with nonisolated inits on Label directly from SwiftUI.