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?
Post
Replies
Boosts
Views
Activity
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?
Is there some way to center text vertically in a fixed size TextEditor, visually it appears that the text by default is "topLeading" and you can only control horizontal alignment with multilineTextAlignment?
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)
}
}