简体   繁体   English

PubNub用法,Swift 2.0更新“模棱两可的使用'下标'” +“排序”

[英]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)
        }
    }
}

As i understood from PubNub updates ... i didn't understood!!! 据我从PubNub更新了解...我不了解!!! 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 关于“下标”的歧义使用,您必须可选地将messageInfo转换为期望的类型

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 我固定排序...就像它迅速1.2

self.data[section]! = self.data[section]!.sort { Utils.compareDateTime($0.date, with: $1.date, order: .OrderedAscending) } 

anyway client issues are left ... 无论如何,剩下的客户问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM