[英]PubNub usage, Swift 2.0 update “Ambiguous use of 'subscript'” + “Sorted”
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更新了解...我不了解!!! 請幫助我找出問題所在,為什么?
也對成員“客戶”的含糊不清
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] {
只有極少數情況下確實需要類型注釋。
我固定排序...就像它迅速1.2
self.data[section]! = self.data[section]!.sort { Utils.compareDateTime($0.date, with: $1.date, order: .OrderedAscending) }
無論如何,剩下的客戶問題...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.