HJH IT Logs

dictionary 에 쉽게 자료 append 하기

naver.how 2019. 1. 16. 13:58
반응형

https://stackoverflow.com/users/7496073/john-montgomery 의 코드를 이용하면 쉽다.

extension Dictionary {

    static func += (lhs: inout [Key:Value], rhs: [Key:Value]) {

        lhs.merge(rhs){$1}

    }

    static func + (lhs: [Key:Value], rhs: [Key:Value]) -> [Key:Value] {

        return lhs.merging(rhs){$1}

    }

}




 _ = json["data"]["summary"].arrayValue.map({

                    VD.s.vdTrendStat?.arrCgmCount += [$0["section"].stringValue : $0["count"].intValue]

                })




.

.

.

        GS.s.tp1?.labelUpperValue.text = String(describing: ((VD.s.vdTrendStat?.arrCgmCount.filter { $0.key == "high" })?.first?.value ?? 0))

반응형