Post

Replies

Boosts

Views

Activity

Reply to Is it possible to get selected text from a Text field?
I tried with onChange, but could not extract the string: var body: some View { TextField("Placehodler", text: $myText, selection: $textSelection) .onChange(of: textSelection) { print("change of selection: \(textSelection)") } } I get change of selection: Optional(SwiftUI.TextSelection(indices: SwiftUI.TextSelection.Indices.selection(Range(Swift.String.Index(_rawBits: 131080)..<Swift.String.Index(_rawBits: 393224))), affinity: SwiftUI.TextSelectionAffinity.upstream)) But that leads nowhere. However, TextSelection doc hints at a way to extract strings, but does not show how to retrieve substrings: struct SuggestionTextEditor: View { @State var text: String = "" @State var selection: TextSelection? = nil var body: some View { VStack { TextEditor(text: $text, selection: $selection) // A helper view that offers live suggestions based on selection. SuggestionsView( substrings: getSubstrings(text: text, indices: selection?.indices)) } } private func getSubstrings( text: String, indices: TextSelection.Indices? ) -> [Substring] { // Resolve substrings representing the current selection... } } That let me hope there is a solution…
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’25
Reply to Swift Form on iOS
Welcome to the forum. Before one can answer, please: post complete code so that we can reproduce (not only the editSource func) format thee code with code formatter tool. As you can see, your present code is just unreadable.
Topic: Community SubTopic: Apple Developers Tags:
Feb ’25
Reply to Extremely offended by Inconsistent Review
Welcome to the forum. You wrote: I got case 4.3 resolved previously, Do you mean you once got a rejection that was finally solved ? If so, I do advise you, when you submit a new release, to mention this past rejection and its resolution and give details (incl the dates of this former rejection/resolution) in the notes for reviewer. That should avoid this type of new rejection.
Feb ’25
Reply to My application has been under review for a very long time, more than 17 days, there is a critical fix in it, how can I speed up the review process?
Welcome to the forum.   I provided the necessary document in response to your request What was the request ? What category of app is it ? It could be a reason beyond the app itself (as it seems it is an update of an existing app on the AppStore), but a verification of your account. Note: the forum is not the right place to address review issues. You have to contact support or continue exchanging with review team (and provide them complete and transparent information).
Feb ’25
Reply to Swift UI Missing argument for parameter in @main app call in List View
Welcome to the forum. The error message is very explicit. You have to pass a Project instance as a parameter, not the structure type itself. @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView(project: Project(name: "dummy", icon: "", isFavorite: true, color: .red, compoundscore: 0)) } // vs project: Project } } Another way is to initialise var project with a dummy instance. No more need to pass parameter in call. Note: when you post code, please use code formatter to make it readable. @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } // no more need for parameter is var is initialised in ContentView } } struct Project: Identifiable { var name: String var icon: String var isFavorite: Bool var color: Color let id = UUID() var compoundscore : Float static func CurrentProjects() -> [Project] { // name should start with lowercase return [Project(name: "Test Project", icon: "🍎", isFavorite: true, color: .red, compoundscore: 4.5), Project(name: "Swimming", icon: "🏊", isFavorite: false, color: .orange, compoundscore: 12.5), Project(name: "Archery", icon: "🏹", isFavorite: false, color: .yellow, compoundscore: 37.5) ] } } struct ProjectRow: View { let project: Project var body: some View { HStack { Text(project.icon) .font(.title) Text(project.name) Spacer() Image(systemName: project.isFavorite ? "heart.fill" : "heart") } } } struct ContentView: View { var CurrentProjectlist: [Project] = Project.CurrentProjects() var project: Project = Project(name: "dummy", icon: "", isFavorite: true, color: .red, compoundscore: 0). // Initial value to avoid having to pass parameter on call var body: some View { NavigationView { List { Section { if #available(iOS 17.0, *) { ForEach(CurrentProjectlist) { project in ProjectRow(project: project) } .listRowBackground( Capsule() .fill(Color(project.color)) .padding(.vertical, 2).padding(.horizontal, 20) ) .listRowSeparator(.hidden) .foregroundColor(.indigo) } else { // Fallback on earlier versions } } header: { Text("CI Projects") } .listRowBackground(Color.blue) .foregroundColor(.black) .listRowInsets(.init(top: 0, leading: 40, bottom: 0, trailing: 40)) .listRowBackground(Color.black) .listSectionSeparatorTint(.yellow) .headerProminence(.increased) .listRowInsets(EdgeInsets.init(top: 0, leading: 50, bottom: 0, trailing: 50)) } .scrollContentBackground(.hidden) .background( Image("cool background") .resizable() .scaledToFill() .clipped() .edgesIgnoringSafeArea(.all) .blur(radius: 3) .overlay(Color.red.opacity(0.2)) ) .environment(\.defaultMinListHeaderHeight, 20) .environment(\.defaultMinListRowHeight, 70) .navigationTitle("Navigator") } } } I tested and it works OK:
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’25
Reply to Immediate crash of Apple Watch simulator when typing a key
Just filed a bug report: Jan 31, 2025 at 7:02 PM – FB16431872 Should be noted that no crash when building the same app, with same Xcode, but through iPhone iOS 17.4 instead of 18.x. Note: I reported a simulator issue (for iOS app with SwiftUI) that does only appear on iOS 18.2 simulators (no access to app settings from iPhone settings) : Dec 27, 2024 at 9:37 AM – FB16175635
Jan ’25