`
init() {
nextOrder = self.AllItems.map{$0.order}.max()
if nextOrder == nil {
nextOrder = 0
}
nextOrder! += 1 // <--- Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
}
`
I have to say, Swift is great - when it works!
How have you defined nextOrder
? Just as an Int?
?
Your code seems to work properly in an existing project of mine:
func abc() {
var nextOrder: Int? = modelData.availableEvents.map { $0.category }.max()
if nextOrder == nil {
nextOrder = 0
}
nextOrder! += 1
}
No errors for me.