在函数内附加数组

时间:2017-09-18 13:19:59

标签: arrays swift3 append

我正在尝试将值附加到函数内的数组中,并在另一个函数中调用该更新的数组,但它不会打印新的附加值。

我正在使用firebase并获取数据库的快照,对其进行排序,查找键值以及附加到hDates

var hDates:Array = [""]

getHistoryPGE() { hDates in
        print(hDates)
        self.hDates = [hDates]
    }

func getHistoryPGE(completion: @escaping (String)->()) {
    let userID = Auth.auth().currentUser?.uid
    let ref = Database.database().reference().child("users").child(userID!)

    ref.child("PostGameEval").observe(.value, with: { (snapshot) in
    if let dict = snapshot.value as? [String : [String: [String: Any]]] {

        let keys = Array(dict.keys)
        var num : Int = 7

        for i in 0..<keys.count {
            if let innerDict = dict[keys[i]] {
                let innerKeys = Array((innerDict).keys)
                let sortedInnerKeys = innerKeys.sorted(by: { $0 > $1} )
                while (sortedInnerKeys.count < num){
                    num -= 1
                }
                for j in 0..<num {
                    if let tempDict = innerDict[sortedInnerKeys[j]] {
                        print(tempDict["1abA"] as! String)
                    }
                }
            }

        }
    }})
}

func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
    let dateString = self.dateFormatter.string(from: date)
    if self.hDates.contains(dateString) {
        return 1
    }
    return 0
}

0 个答案:

没有答案