Fix crash when inserting poll from draft created in share sheet

This commit is contained in:
Shadowfacts 2023-04-23 10:22:44 -04:00
parent 3bba4edb45
commit 49334766ef
1 changed files with 12 additions and 10 deletions

View File

@ -16,16 +16,6 @@ public class Poll: NSManagedObject {
@NSManaged public var draft: Draft @NSManaged public var draft: Draft
@NSManaged public var options: NSMutableOrderedSet @NSManaged public var options: NSMutableOrderedSet
init(context: NSManagedObjectContext) {
super.init(entity: context.persistentStoreCoordinator!.managedObjectModel.entitiesByName["Poll"]!, insertInto: context)
self.multiple = false
self.duration = 24 * 60 * 60 // 1 day
self.options = [
PollOption(context: context),
PollOption(context: context),
]
}
public var pollOptions: [PollOption] { public var pollOptions: [PollOption] {
get { get {
options.array as! [PollOption] options.array as! [PollOption]
@ -35,6 +25,18 @@ public class Poll: NSManagedObject {
} }
} }
public override func awakeFromInsert() {
super.awakeFromInsert()
self.multiple = false
self.duration = 24 * 60 * 60 // 1 day
if let managedObjectContext {
self.options = [
PollOption(context: managedObjectContext),
PollOption(context: managedObjectContext),
]
}
}
} }
extension Poll { extension Poll {