attempt to bridge an implicitly

2017-12-14  本文已影响67人  sasky2008

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
                ]
}

就可以了.

上一篇下一篇

猜你喜欢

热点阅读