Post

Replies

Boosts

Views

Activity

Reply to Issue with UIDatePicker causing Application Crash
I repeated the test, with a new datePicker, without any connection. No issue either. You have probably an issue in code. Did you try to do a Clean Build Folder ? If not working, could you send the code of the ViewController ? I see you have defined constraints. Could you show them ? There is a reference to a TableView. Have you created any ? If so, error may lie there. Please post the code in that case.
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’24
Reply to Separate each paragraph in a list
Welcome to the forum. You should show the code you tried so far, that's much easier to build a precise answer. You want to separate in a List. SwiftUI List ? Let's try any way. How are paragraphs delimited ? By a newLine character (\n) ? If so, here is a way to do it: let myLongText = """ Hello, this is a text with several paragraphs. I want to split them into distinct paragraphs. I'd like to separate each paragraph of a text in a list, I'm trying to find how to do it, I know it's certainly a dumb question but I'm new at coding, please be kind haha, may someone help me? """ let paragraphArray = myLongText.components(separatedBy: CharacterSet.newlines) print(paragraphArray) In SwiftUI code, you would use as follows: struct ContentView: View { let myLongText = """ Hello, this is a text with several paragraphs. I want to split them into distinct paragraphs. I'd like to separate each paragraph of a text in a list, I'm trying to find how to do it, I know it's certainly a dumb question but I'm new at coding, please be kind haha, may someone help me? """ @State var paragraphArray: [String] = [] var body: some View { VStack { Spacer() List(paragraphArray, id: \.self) { line in Text("\(line)") } Spacer() Button(action: { paragraphArray = myLongText.components(separatedBy: CharacterSet.newlines) }) { Text("Split") } } } } And get: If that answers your question, don't forget to close the thread by marking the answer as correct. Otherwise, please explain the problem.
Feb ’24
Reply to using array[struct] with @Binding in ForEach
Your title says @Binding in ForEach But your code uses List, not ForEach Please show more code (and as Text, not only screen shot). A few questions: why do you need a Binding here ? You don't modify accountItems in thais view. How is AccountItemView defined ? If you have an forDisplay var declared, you should call AccountItemView(forDisplay: accountItem) So, missing more context, just a guess. Try something like this: struct AccountListView: View { @Binding var accountItems: [AccountItem] var body: some View { List(accountItems, id: \.self) { accountItem in AccounItemView(forDisplay: accountItem) } // <<-- id \.self here } } With ForEach, you should have: ForEach(accountItems, id: \.self) { item in AccounItemView(forDisplay: item) } But I suspect your Binding to be more @State, and Binding being inside AccounItemView Then you should have code like this: struct AccounItemView: View { @Binding var forDisplay: AccountItem var body: some View { Text("\(forDisplay.someProperty)") } } struct AccountListView: View { @State var accountItems: [AccountItem] var body: some View { List($accountItems, id: \.self) { $item in AccounItemView(forDisplay: $item) } // or, with ForEach: ForEach($accountItems, id: \.self) { $item in AccounItemView(forDisplay: $item) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to Playground Submission Question
It is upto you. No rule about it. I would suggest to leave most of the comments that helps understand the code. That's a good practice that can only please the reviewer if he/she looks at the code and that will help you maintain your code later if you have to. But don't leave personal comments. Good luck for the challenge.
Feb ’24