Swift enum segmentation fault

断了今生、忘了曾经 提交于 2019-12-11 18:35:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!