无法转换通话结果类型' _?'预期类型' [UInt]'

时间:2016-04-19 14:05:17

标签: swift swift2 swift2.2

self.mapper.identityIdsForQuickbloxUserIds(userIDs.map{($0 as! NSNumber).unsignedLongValue}, completion: { identityIdsMapping, error in
  

无法转换通话结果类型' _?'预期类型' [UInt]'

userIDsNSSet

这是一个函数:

func identityIdsForQuickbloxUserIds(userIds:[UInt], completion:(identityIdsMapping:[UInt: String]?, error:NSError?) -> Void)

如何以正确的方式转换它?

这是外部函数,它为我返回设置:

- (void)allDialogsWithPageLimit:(NSUInteger)limit
                extendedRequest:(QB_NULLABLE NSDictionary *)extendedRequest
                 iterationBlock:(void(^QB_NULLABLE_S )(QBResponse *QB_NONNULL_S response, NSArray QB_GENERIC(QBChatDialog *) *QB_NULLABLE_S dialogObjects, NSSet QB_GENERIC(NSNumber *) * QB_NULLABLE_S dialogsUsersIDs, BOOL * QB_NONNULL_S stop))iterationBlock
                     completion:(void(^QB_NULLABLE_S)(QBResponse * QB_NONNULL_S response))completion;

如你所见,我们从这里得到了NSSet:

NSSet QB_GENERIC(NSNumber *) * QB_NULLABLE_S dialogsUsersIDs

该方法来自QuickBlox SDK

2 个答案:

答案 0 :(得分:1)

示例1:

这是一个简单的例子:

    identityIdsForQuickbloxUserIds([1,2,3]) { dictionary, error in


    }

示例2:

    let x = NSSet(array: [1, 2, 3]).map { $0 as! UInt }

    identityIdsForQuickbloxUserIds(x) { dictionary, error in


    }

答案 1 :(得分:1)

userIDs是可选的Set<NSNumber>?而不是Set<NSNumber>所以你需要首先打开这样的东西

var ids = userIDs?.map { $0.unsignedLongValue } ?? [UInt]()

...

identityIdsForQuickbloxUserIds(ids, ...)