Post

Replies

Boosts

Views

Activity

Reply to Pass data to an @Observable model
The 3rd option looks good. .onAppear() and .task{} are better suited for processing data when the view is displayed than the init{} function. However, a query could be created in init{} to load data. There are different ways to do this; it always depends on what makes sense for the situation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
4w
Reply to Pass data to an @Observable model
Do you need a view model? A view can include a view model, but it doesn't have to. I only use view models when complex validations or extra data are loaded that require additional effort. Otherwise, @Query is sufficient to load the data. I assume the details aren't relevant in the parent view and therefore haven't been loaded yet. In the DetailView, you could use @Query private var details: [CarDetails] init(carID: UUID) { let predicate = #Predicate<CarDetails> { $0.id = carID} _details = Query (filter: predicate) } I recommend watching Stewart Lynch's videos on YouTube. He explains many topics in an easy-to-understand way.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
4w
Reply to Pass data to an @Observable model
Hi, in the parent view the data is like this @State private var value: Int = 1 and in the child view @Binding var value: Int In this case, the parent view controls the data, and the child view can use and modify it. Is that what you mean? Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’26
Reply to onChange(of:initial:_:) changes when same value assigned
Hi, Is your field optional? If it's optional, the value will be set to nil when it's removed. Otherwise, the field will never be empty and will always retain its value, thus not triggering any change unless that value is different. I have created a small sample view. struct OnChangeView: View { @State private var value: Int? = 1 @State private var value2: Int = 2 var body: some View { VStack { TextField("val 1", value: $value, format: .number) TextField("val 2", value: $value2, format: .number) } .onChange(of: value, initial: true) { print("value 1", value) } .onChange(of: value2, initial: false) { print("value 2", value2) } .onAppear { value = 1 value2 = 2 } } } #Preview { OnChangeView() } Do you have an example that's different? Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’26
Reply to TextField format, integer limits and fractions not applied
I wrote a separate field component to solve the percent field problem. Apparently, this is generally necessary with decimal numbers. Or is there a simpler solution? Decimal point formatting is a general problem and affects not only percentages but all floating-point numbers. Whether format or formatter is used is irrelevant. I have a formatter that only allows values ​​up to a maximum and has one decimal place. let limitedFormatter: NumberFormatter = { let formatter = NumberFormatter() formatter.minimum = 0 formatter.maximum = 13.9 formatter.generatesDecimalNumbers = true formatter.maximumFractionDigits = 1 formatter.numberStyle = .decimal return formatter }() When the focus of the field is removed, the formatter becomes active and the behavior is as expected. However, if the view is immediately exited using dismiss(), as in the previous example, it doesn't work. That's not entirely correct, because the formatter only does half its job and checks whether the maximum has been exceeded, but ignores the decimal places, as in the other example. However, it seems to work if you append arbitrary decimal places to the maximum value. Example: the maximum is 13.9, and if I enter 13.9888888, it becomes 13.9. It gets even stranger: if you set a minimum value in the formatter and then enter a value outside that range, the result is nil. With a minimum value of 0, the first digit is used, as long as it's not higher than the maximum value; otherwise, the result is nil again. Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’26
Reply to TextField format, integer limits and fractions not applied
I have a solution I've already thought of, but I'm not satisfied with it because I would have to implement it everywhere this problem occurs. At least the onChange() method in the View. Before posting the answer here, I was able to identify the bug more precisely. More about this at the end of the post. Extension on Double for rounding: extension Double { func rounded(toPlaces places: Int, rule: FloatingPointRoundingRule = .down) -> Double { let divisor = pow(10.0, Double(places)) return (self * divisor).rounded(rule) / divisor } } A max percent value in the View: private let maxPercent = 0.8 onChange of the value: .onChange(of: percentValue) { checkPercentValue() } The check function: private func checkPercentValue() { let mf = modf(percentValue).1 var val = mf.rounded(toPlaces: 3) if val > maxPercent { val = maxPercent } percentValue = val } Not good, but it seems to work. Yes, at first glance it seems to work, but when I enter values ​​above 100 it no longer works. The function checkPercentValue() works correctly and sets percentValue to 0.0, but the field does not respond to this. The problem is: .percent.precision(.integerAndFractionLength(integerLimits: 0...2, fractionLimits: 0...1)) Simply using .percent, however, works. Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’26
Reply to SwiftData Crashes After Modifying The VersionedSchema More Than Once
Hello, this is not a problem with Xcode as you found out, but with the data that already exists in your database. Suppose you have 5 fields and some records in the database. You are adding a field that is NOT optional. What should happen to the records where the field is empty? However, the field cannot be empty. There are various strategies to deal with this, but I'm not sure it's easy with core data.
Topic: App & System Services SubTopic: iCloud Tags:
Dec ’23
Reply to Pass data to an @Observable model
The 3rd option looks good. .onAppear() and .task{} are better suited for processing data when the view is displayed than the init{} function. However, a query could be created in init{} to load data. There are different ways to do this; it always depends on what makes sense for the situation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
4w
Reply to Pass data to an @Observable model
Do you need a view model? A view can include a view model, but it doesn't have to. I only use view models when complex validations or extra data are loaded that require additional effort. Otherwise, @Query is sufficient to load the data. I assume the details aren't relevant in the parent view and therefore haven't been loaded yet. In the DetailView, you could use @Query private var details: [CarDetails] init(carID: UUID) { let predicate = #Predicate<CarDetails> { $0.id = carID} _details = Query (filter: predicate) } I recommend watching Stewart Lynch's videos on YouTube. He explains many topics in an easy-to-understand way.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
4w
Reply to Pass data to an @Observable model
Hi, in the parent view the data is like this @State private var value: Int = 1 and in the child view @Binding var value: Int In this case, the parent view controls the data, and the child view can use and modify it. Is that what you mean? Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’26
Reply to onChange(of:initial:_:) changes when same value assigned
Hi, Is your field optional? If it's optional, the value will be set to nil when it's removed. Otherwise, the field will never be empty and will always retain its value, thus not triggering any change unless that value is different. I have created a small sample view. struct OnChangeView: View { @State private var value: Int? = 1 @State private var value2: Int = 2 var body: some View { VStack { TextField("val 1", value: $value, format: .number) TextField("val 2", value: $value2, format: .number) } .onChange(of: value, initial: true) { print("value 1", value) } .onChange(of: value2, initial: false) { print("value 2", value2) } .onAppear { value = 1 value2 = 2 } } } #Preview { OnChangeView() } Do you have an example that's different? Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’26
Reply to TextField format, integer limits and fractions not applied
I wrote a separate field component to solve the percent field problem. Apparently, this is generally necessary with decimal numbers. Or is there a simpler solution? Decimal point formatting is a general problem and affects not only percentages but all floating-point numbers. Whether format or formatter is used is irrelevant. I have a formatter that only allows values ​​up to a maximum and has one decimal place. let limitedFormatter: NumberFormatter = { let formatter = NumberFormatter() formatter.minimum = 0 formatter.maximum = 13.9 formatter.generatesDecimalNumbers = true formatter.maximumFractionDigits = 1 formatter.numberStyle = .decimal return formatter }() When the focus of the field is removed, the formatter becomes active and the behavior is as expected. However, if the view is immediately exited using dismiss(), as in the previous example, it doesn't work. That's not entirely correct, because the formatter only does half its job and checks whether the maximum has been exceeded, but ignores the decimal places, as in the other example. However, it seems to work if you append arbitrary decimal places to the maximum value. Example: the maximum is 13.9, and if I enter 13.9888888, it becomes 13.9. It gets even stranger: if you set a minimum value in the formatter and then enter a value outside that range, the result is nil. With a minimum value of 0, the first digit is used, as long as it's not higher than the maximum value; otherwise, the result is nil again. Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’26
Reply to TextField format, integer limits and fractions not applied
I have a solution I've already thought of, but I'm not satisfied with it because I would have to implement it everywhere this problem occurs. At least the onChange() method in the View. Before posting the answer here, I was able to identify the bug more precisely. More about this at the end of the post. Extension on Double for rounding: extension Double { func rounded(toPlaces places: Int, rule: FloatingPointRoundingRule = .down) -> Double { let divisor = pow(10.0, Double(places)) return (self * divisor).rounded(rule) / divisor } } A max percent value in the View: private let maxPercent = 0.8 onChange of the value: .onChange(of: percentValue) { checkPercentValue() } The check function: private func checkPercentValue() { let mf = modf(percentValue).1 var val = mf.rounded(toPlaces: 3) if val > maxPercent { val = maxPercent } percentValue = val } Not good, but it seems to work. Yes, at first glance it seems to work, but when I enter values ​​above 100 it no longer works. The function checkPercentValue() works correctly and sets percentValue to 0.0, but the field does not respond to this. The problem is: .percent.precision(.integerAndFractionLength(integerLimits: 0...2, fractionLimits: 0...1)) Simply using .percent, however, works. Christian
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’26
Reply to AVSpeechSynthesizer pulls words out of thin air.
It seems we'll just have to live with the bugs, and Apple isn't offering any fixes. It's the same with deleting files and to try to put them back, that bug is over 10 years old.
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to iOS - record audio fails to record
Hi, I copied the code and permission to a macOS test app and the code works. I've read various statements about whether the audio recorder can be used in the iOS simulator. It seems like it's not possible, or is there a setting missing? Thank you
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to trashItem, recycle, but no put back option...it depends
Hello Quinn, thank you for your reply. I hope that this will change something and the problem will be addressed again. NSWorkspace recycle initially looked more promising than FileManager trashItem, but that was not the case. But it has the advantage that an array can be passed. Thank you
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Feb ’25
Reply to SwiftData Crashes After Modifying The VersionedSchema More Than Once
Hello, this is not a problem with Xcode as you found out, but with the data that already exists in your database. Suppose you have 5 fields and some records in the database. You are adding a field that is NOT optional. What should happen to the records where the field is empty? However, the field cannot be empty. There are various strategies to deal with this, but I'm not sure it's easy with core data.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Dec ’23