Post

Replies

Boosts

Views

Activity

SwiftUI Table column widths cannot be saved
I have a macOS app made with SwiftUI where I want to show a list of data in a tabular fashion. SwiftUI Table seems to be the only built-in component that can do this. I would like to let the user size the columns and have their widths restored when the app is relaunched. I can find no documentation on how to do this and it does not seem to be saved and restored automatically. I can find no way to listen for changes in the column widths when the user resizes and no way to set the size from code. For a macOS app it seems that the only way to set the width of a column is to use e.g. .width(min: 200, max: 200). This in effect disables resizing of the column. It seems that idealSize is totally ignored on macOS. Any suggestions?
2
2
222
3w
How to debug missing environment values
I have a custom environment key defined: struct MyCustomKey: EnvironmentKey { static let defaultValue = MyCustom.dummy } extension EnvironmentValues { var myCustom: MyCustom { get { self[MyCustomKey.self] } set { self[MyCustomKey.self] = newValue } } } and pass it on the top level: let myCustomInstance = MyCustom() @main struct ThygeApp: App { var body: some Scene { WindowGroup { MainWindow() .environment(\.myCustom, myCustomInstance) } } } I really do not want it to use the default instance ever, I want it to be specified explicitly. Is there a way to have it fail on use if it is not specified in the environment? I have made it so that the .dummy instance does a fatalError() and that works so far as it halt the app. But there are no hints in the stack track as to where the offending code is - where do I use the environment value without passing it like I do here .environment(\.myCustom, myCustomInstance) The only solution to find the offending use is to add an assert() to all func defined in MyCustom. That seems cumbersome and error prone. Is there another way?
2
0
257
Jul ’24
Multiple Y axis in single chart?
I have two data sets and I want to show them in the same chart. Both data sets are time based (x axis) and with same time range. They have different units of measure and scaling (y axis). Is it possible to show both data sets in the same chart, but with two different y axis definitions? I have tried to overlay two independent charts but then the two charts are not aligned as I configure one with Y axis to the left and the other with Y axis to the right. Any ideas how to make this happen?
1
0
1.9k
Jul ’22