gpt4 book ai didi

ios - PubNub使用,Swift 2.0更新 "Ambiguous use of '下标'"+ "排序》

转载 作者:行者123 更新时间:2023-11-29 00:59:00 24 4
gpt4 key购买 nike

func client(client: PubNub, didReceiveMessage message: PNMessageResult) {
if message.data.subscribedChannel == self.channel {
if let messageInfo: AnyObject = message.data.message {
let type = (messageInfo["type"] as! String) //Ambiguous use of 'subscript'
let date = (messageInfo["date"] as! String).getDateString() //Ambiguous use of 'subscript'
let messageText = messageInfo["message"] as! String //Ambiguous use of 'subscript'
let fileUrl: String? = type == "text" ? nil : "http://college.audio-visueel.com/" + (messageInfo["fileUrl"] as! String)
let from: ConversationMessage.sendFromType = (messageInfo["userID"] as! String) == self.userID ? .Me : .Other //Ambiguous use of 'subscript'
let image = messageInfo["userPhoto"] as! String //Ambiguous use of 'subscript'
let name = messageInfo["userName"] as! String //Ambiguous use of 'subscript'
if data[date] != nil {
data[date]!.append(ConversationMessage(userID: messageInfo["userID"] as! String,text: messageText, from: from, personImage: image, personName: name, date: messageInfo["date"] as! String, type: type, fileUrl: fileUrl))
} else {
data[date] = [ConversationMessage(userID: messageInfo["userID"] as! String,text: messageText, from: from, personImage: image, personName: name, date: messageInfo["date"] as! String, type: type, fileUrl: fileUrl)]
}
for section in self.sections {
self.data[section]! = sorted(self.data[section]!) { Utils.compareDateTime($0.date, with: $1.date, order: .OrderedAscending) //'sorted' is unavailable: call the 'sort()' method on the collection}
}
searchedSections = sections
searchedData = data
tableView.reloadData()
tableViewScrollToBottom(false)
}
}
}

正如我从 PubNub 更新中了解到的那样……我不明白!!!请帮我找出问题所在,为什么? enter image description here

还有 对成员“客户”的模糊引用

    client.historyForChannel(channel, start: nil, end: nil, limit: 10, withCompletion: {
(result: PNHistoryResult , status: PNErrorStatus ) -> Void in
let messages = result.data.messages
for message in messages {
let date = (message["date"] as! String).getDateString()
if !contains(self.sections, date) {
self.sections.append(date)
self.data[date] = [ConversationMessage]()
}
}...

但它是在程序开始时声明的...

 var client: PubNub!

最佳答案

关于“下标”的不明确使用,您必须将 messageInfo 强制转换为预期类型

if let messageInfo = message.data.message as? [String:AnyObject] {

只有少数情况真正需要类型注释。

关于ios - PubNub使用,Swift 2.0更新 "Ambiguous use of '下标'"+ "排序》,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260736/

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