When I add a TextField with @FocusState to a toolbar, I noticed that setting focus = false doesn't cause the form to lose focus
If I move the TextField out of the toolbar setting focus = false works fine. How can I unfocus the text field when the cancel button is tapped?
Minimal example tested on Xcode Version 26.0 beta 6 (17A5305f):
import SwiftUI
struct ContentView: View {
@State private var text: String = ""
@FocusState private var focus: Bool
var body: some View {
NavigationStack {
List {
Text("Test List")
}
.toolbar {
ToolbarItem(placement: .bottomBar) {
TextField("Test", text: $text)
.padding(.horizontal)
.focused($focus)
}
ToolbarItem(placement: .bottomBar) {
Button(role: .cancel) {
focus = false // THIS DOESN'T WORK!
}
}
}
}
}
}
#Preview {
ContentView()
}```
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I am trying to add CloudKit sharing to my app using the new iOS 15 share method
https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-sharemanagedobjects
In the app there are 3 core data entities (Folder, Item, Comment) with the following relationships:
A Folder contains many Items
An Item has many Comments
I want to use CloudKit to share just the Item entity, not any of its relationships. Is this possible to do with the share(_:to:completion:) method?
Currently, when I pass an Item to the share method it also includes the Folder and Comments in the CKShare. How do I prevent this?
A similar question was posted here with no response: https://developer.apple.com/forums/thread/697630
I am trying to add CloudKit sharing to my app using the new iOS 15 share method https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-share
In the app there are 3 core data entities (Folder, Item, Comment) with the following relationships:
A Folder contains many Items
An Item has many Comments
I want to use CloudKit to share just the Item entity, not any of its relationships. Is this possible to do with the share(_:to:completion:) method?
Currently, when I pass an Item to the share method it also includes the Folder and Comments in the CKShare. How do I prevent this?