美文网首页
attempt to bridge an implicitly

attempt to bridge an implicitly

作者: sasky2008 | 来源:发表于2017-12-14 13:41 被阅读67次

    attempt to bridge an implicitly unwrapped optional containing nil

    原因是因为

    class AA 继承与 class A (class A 是一个 OC 类).
    有个属性.

    @property (nonatomic, copy, readonly) NSString *conversationId;
    

    在 class AA 里面

    let params = [ "USER_ID":self.peerID,
                   "CONVERSATION_ID":self.conversationId,
                   "CONVERSATION_TYPE":self.messageType
                    ]
    

    就崩溃了, 因为 "self.conversationId == nil"
    因为OC的属性可能是空的...
    相当于

    let params = [ "USER_ID":self.peerID!,
                   "CONVERSATION_ID":self.conversationId!,
                   "CONVERSATION_TYPE":self.messageType!
                    ]
    

    所以需要提前判定

    if self.conversationId != nil {
        let params = [ "USER_ID":self.peerID,
                  "CONVERSATION_ID":self.conversationId,
                  "CONVERSATION_TYPE":self.messageType
                    ]
    }
    

    就可以了.

    相关文章

      网友评论

          本文标题:attempt to bridge an implicitly

          本文链接:https://www.haomeiwen.com/subject/kbckwxtx.html