Posts

Post not yet marked as solved
5 Replies
Use .task to assign the initial focused field instead of using .onAppear TextField("Placeholder", text: $text)       .focused($focusedField, equals: .field)       .task {         self.focusedField = .field }
Post marked as solved
1 Replies
Follow this solution on StackOverflow to fetch data from CoreData for iOS 14 widgets - https://stackoverflow.com/a/63945538/10887876
Post not yet marked as solved
8 Replies
As I know, this is the best way to add a placeholder text to TextEditor in SwiftUI struct ContentView: View { 		@State var text = "Type here" 		 		var body: some View { 				TextEditor(text: self.$text) 						// make the color of the placeholder gray 						.foregroundColor(self.text == "Type here" ? .gray : .primary) 						 						.onAppear { 								// remove the placeholder text when keyboard appears 								NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { (noti) in 										withAnimation { 												if self.text == "Type here" { 														self.text = "" 												} 										} 								} 								 								// put back the placeholder text if the user dismisses the keyboard without adding any text 								NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { (noti) in 										withAnimation { 												if self.text == "" { 														self.text = "Type here" 												} 										} 								} 						} 		} }
Post not yet marked as solved
4 Replies
Did you guys find any solution for this?