Post

Replies

Boosts

Views

Activity

HSplitView does not redraw correctly
I have a view with a HSplitView containing three sub-views, a central panel that contains toggles to hide / show a left and right side pane. If I hide any side panel, the central panel does not redraw correctly. A slight nudge on the app will make it redraw correctly. The toggles do not work until you have triggered a redraw, I guess internally they are at the "new" location but visually at the "old". With HStack instead of HSplitView everything works as expected. Here is a simplified example of the code, any suggestions ... // HSplitView does not work, HStack work OK         HSplitView {             if showLeftPane {                 Text("Left pane").frame(minWidth: 200, idealWidth: 200, maxHeight: .infinity, alignment: .topLeading).background(Color.yellow)             }             VStack {                 Toggle("Left show", isOn: $showLeftPane)                 Toggle("Right show", isOn: $showRightPane)             }.frame(maxWidth: .infinity, maxHeight: .infinity).background(Color.green)             if showRightPane {                 Text("Right pane").frame(minWidth: 200, idealWidth: 200, maxHeight: .infinity, alignment: .topLeading).background(Color.blue)             }         }
0
0
660
Jul ’20
JSON encoding of AttributedString with custom attributes
I have implemented custom attributes for an AttributedString and successfully converted to NSAttributedString and used in NSTextView with custom coloring and background, works nicely! What does not work is encoding the AttributedString to JSON. The custom attributes are not coded. I use a plain JSON encode like this: let data = JSONEncoder().encode(object) I assume some option is needed for the encoder to deal with the custom attributes (like when converting to NSAttributedString), but I have not been able to find any documentation on how to do this. Any suggestions?
1
0
2.2k
Sep ’21
@ObservationIgnored weak var - must be initialised?
I understand that @Observable currently requires all properties to be initialised. However I am surprised that opting out of observation does not work: @Observable class Assessment { var name = "" var processes: [Process] = [] } @Observable class Process { var name = "" @ObservationIgnored weak var parent: Assessment? } The error message is Return from initializer without initializing all stored properties from the Process class. Any suggestions?
0
1
929
Jul ’23