Код: Выделить всё
Button
{
onPresentCommentInDocument(commentSource, commentSource.passages, commentSource.document)
}
label:
{
Image(systemName: "document")
}
Код: Выделить всё
onPresentCommentInDocument:
{
commentSource, document, passages in
self.commentSourceToEdit = commentSource
self.commentSourceDocumentToPresent = document
self.commentSourcePassagesToEdit = passages
})
Код: Выделить всё
private var documentToPresent: Binding
{
Binding(get:
{
if self.commentSourceToEdit != nil && self.commentSourcePassagesToEdit != nil,
let commentSourceDocumentToPresent = self.commentSourceDocumentToPresent
{
commentSourceDocumentToPresent
}
else
{
self.interiorDocumentToPresent
}
},
set:
{
newValue in
if (newValue == nil)
{
self.commentSourceDocumentToPresent = nil
self.commentSourceToEdit = nil
self.commentSourcePassagesToEdit = nil
self.interiorDocumentToPresent = nil
}
})
}
< /code>
documentToPresentКод: Выделить всё
if let commentSourcePassagesToEditBinding = Binding(self.$commentSourcePassagesToEdit)
{
commentSourcePassagesToEditBinding.wrappedValue.append(passageToEdit)
self.commentSourceToEdit?.passages?.append(passageToEdit)
}
< /code>
I have to append to the binding so when I reference it throughout the structure it is up to date and also append to the array through its parent object so it will save and update in the model.
These feels off to me and I'm wondering if there is a better way to do it. I have tried passing these properties (commentSourceToEditПодробнее здесь: https://stackoverflow.com/questions/797 ... ct-as-a-bi
Мобильная версия