forked from shadowfacts/Tusker
Fix crash when removing the same poll option multiple times
SwiftUI doesn't detect updates to CoreData objects when directly mutating the NSMutableOrderedSet of a relationship Closes #458
This commit is contained in:
parent
3caa419659
commit
d481ef6c9f
|
@ -34,11 +34,16 @@ class PollController: ViewController {
|
|||
}
|
||||
|
||||
private func moveOptions(indices: IndexSet, newIndex: Int) {
|
||||
poll.options.moveObjects(at: indices, to: newIndex)
|
||||
// see AttachmentsListController.moveAttachments
|
||||
var array = poll.pollOptions
|
||||
array.move(fromOffsets: indices, toOffset: newIndex)
|
||||
poll.options = NSMutableOrderedSet(array: array)
|
||||
}
|
||||
|
||||
private func removeOption(_ option: PollOption) {
|
||||
poll.options.remove(option)
|
||||
var array = poll.pollOptions
|
||||
array.remove(at: poll.options.index(of: option))
|
||||
poll.options = NSMutableOrderedSet(array: array)
|
||||
}
|
||||
|
||||
private var canAddOption: Bool {
|
||||
|
|
|
@ -52,6 +52,11 @@ struct EmojiTextField: UIViewRepresentable {
|
|||
if text != uiView.text {
|
||||
uiView.text = text
|
||||
}
|
||||
if placeholder != uiView.attributedPlaceholder?.string {
|
||||
uiView.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [
|
||||
.foregroundColor: UIColor.secondaryLabel,
|
||||
])
|
||||
}
|
||||
|
||||
context.coordinator.text = $text
|
||||
context.coordinator.maxLength = maxLength
|
||||
|
|
Loading…
Reference in New Issue