Swift error when trying to access Dictionary: `Could not find member 'subscript'`

后端 未结 4 964
半阙折子戏
半阙折子戏 2021-02-04 08:08

This won\'t compile: \"enter I\'ve tried a couple different things; different ways of declaring th

4条回答
  •  眼角桃花
    2021-02-04 08:50

    func valueForCurrency(currency :String, exchange :String) -> Float? {
        if let exchanges = response["current_rates"] as? Dictionary {
            if let currencies = exchanges[exchange] as? Dictionary {
                return currencies[currency] as? Float
            }
        }
        return nil
    }
    

提交回复
热议问题