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)
}
}
}
As i understood from PubNub updates ... i didn't understood!!! Please help me to find out what is wrong and why?
also Ambiguous reference to member 'client'
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]()
}
}...
but it was declared at the beginning of a program ...
var client: PubNub!
Regarding Ambiguous use of 'subscript' you have to optional cast messageInfo
down the to the expected type
if let messageInfo = message.data.message as? [String:AnyObject] {
There are only a few cases where type annotations are really needed.
I fixed sorted... like it was in swift 1.2
self.data[section]! = self.data[section]!.sort { Utils.compareDateTime($0.date, with: $1.date, order: .OrderedAscending) }
anyway client issues are left ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.