使用PromiseKit,我尝试将when
块的输出设置为局部变量allChatRooms
var allChatRooms : [ChatRoom]
var chatRoomIDs : [String:Bool] = ...
firstly {
when(resolved: chatRoomIDs.map{fetchChatRoom(id: $0.key)})
}.then { chatRooms -> Void in
allChatRooms = chatRooms <-- Error here
}
编译器错误是:
注:(
ChatRoom
和KChatRoom
相同)如何将结果设置为
allChatRooms
变量? 最佳答案
解决方案很简单,我输入了错误的when
块。相反,它应该是fulfilled
而不是resolved
when(fulfilled: chatRoomIDs.map{fetchChatRoom(id: $0.key)})