I have the following event model:
class Event: NSObject, NSCoding {
var name: String
var category: Category
enum Category: String {
case Call = "Call"
case Coaching = "Coaching"
}
}
When a user updates their selection of the category enum it crashes with the error: fatal error: unexpectedly found nil while unwrapping an Optional value. However when I print "selected category" I get the correct response: "Call."
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if saveButton === sender {
let name = eventNameTextField.text ?? ""
let category = eventCategoryLabel.text!
if let cat = Event.Category(rawValue:category) {
print("selected category: \(cat)")
event = Event(name: name, category: cat)
}
}
}
Am I missing something when it comes to saving selecting strings as enum options? Thanks in advance for everyone's time!