仅从unwraps期权中贬低;你的意思是用'!'?

时间:2016-04-19 12:13:13

标签: swift swift2 swift2.2

我有这个奇怪的错误,并且没有任何想法来解决它。

guard let theDialogObjects = dialogObjects as! [QBChatDialog]
  

来自'[QBChatDialog]?'到'[QBChatDialog]'才打开   自选项目;你的意思是用'!'吗?

代码来自此处:https://github.com/QuickBlox/q-municate-services-ios/blob/master/QMChatService/QMChatService/QMChatService.m

- (void)allDialogsWithPageLimit:(NSUInteger)limit
                extendedRequest:(NSDictionary *)extendedRequest
                 iterationBlock:(void(^)(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, BOOL *stop))iterationBlock
                     completion:(void(^)(QBResponse *response))completion {

这就是我在Swift中使用它的方式:

QMServicesManager.instance().chatService.allDialogsWithPageLimit(UInt.max, extendedRequest: ["type":String(QBChatDialogType.Private.rawValue)], iterationBlock: { (response, dialogObjects, userIDs, stop) in

      guard let theDialogObjects = dialogObjects as! [QBChatDialog]{
        return
      }

1 个答案:

答案 0 :(得分:3)

从错误消息中您不是要尝试更改类型,只需检查值是否为零,所以您的检查应该是:

guard let theDialogObjects = dialogObjects else ...