gpt4 book ai didi

swift - 从仅解包选项中向下转换;您是要使用 '!' 吗?

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:02 24 4
gpt4 key购买 nike

我有这个奇怪的错误,不知道如何修复它。

guard let theDialogObjects = dialogObjects as! [QBChatDialog]

Downcast from '[QBChatDialog]?' to '[QBChatDialog]' only unwraps optionals; did you mean to use '!'?

代码来自这里: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
}

最佳答案

从错误消息中您并没有尝试更改类型,只是检查值不为 nil,因此您的检查应该是:

guard let theDialogObjects = dialogObjects else ...

关于swift - 从仅解包选项中向下转换;您是要使用 '!' 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36718046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com