问题
I have to following code:
groupListeningObject = NSNotificationCenter.defaultCenter().addObserverForName(groupJoinedOrLeftNotificationName, object: nil, queue: nil) { [weak self] notification in
if let notificationArray = notification.object as? [AnyObject] {
let joinedOrLeft = JoinOrLeave(rawValue: notificationArray[1] as Int)
if joinedOrLeft == .Join {
//some code
}
}
}
This gives a segmentation fault error, but if I modify the if statement as follows:
if joinedOrLeft == JoinOrLeave.Join
there will be no error. I thought I can use the short version of an enum in an if statement, but the compiler doesn't like it. Why can't I use the shorter version of enums, what am I missing here?
来源:https://stackoverflow.com/questions/28559192/swift-enum-segmentation-fault