I took CKShare with Zone example - https://github.com/apple/sample-cloudkit-sharing
Modified it a little bit so code looks like this:
struct ResourceView: View {
@State private var showingShare: Bool = false
@State private var shareView: CloudSharingView?
...
var body: some View {
HStack {
Button(action: {
Task {
let (share,container) = try! await shareConfiguration()
shareView = CloudSharingView(container: container, share: share)
showingShare = true
}
}) {
Label("Share", systemImage: "circle")
}
...
.sheet(isPresented: $showingShare) {
if let shareView = shareView {
shareView
} else {
Text("No sheet to show")
}
}
And the first time I click on Share button I am getting "No sheet to show" despite showingShare boolean being set after shareView variable. Presumably because shareView is nil.
The second time I click on Share button it shows the sharing view.