Ios 如何根据Swift 4中UISlider的值使用JSON中的数据更改UITextfield文本?
现在,我对UIText字段进行了硬编码,并根据UISlider上的值进行更改Ios 如何根据Swift 4中UISlider的值使用JSON中的数据更改UITextfield文本?,ios,json,swift,uislider,Ios,Json,Swift,Uislider,现在,我对UIText字段进行了硬编码,并根据UISlider上的值进行更改 @IBAction func sliderValueChanged(_ sender: UISlider) { let currentValue = Int(sender.value) levelLabel.text = "Food Level \(currentValue)" if currentValue == 1 { foodDescription.text = "He
@IBAction func sliderValueChanged(_ sender: UISlider) {
let currentValue = Int(sender.value)
levelLabel.text = "Food Level \(currentValue)"
if currentValue == 1 {
foodDescription.text = "Healthy Vegetables: (raw, steamed, roasted, frozen). "
我能够连接到RESTAPI并解析JSON结果
现在,滑块的值从1到6
JSON的结构如下所示:
{
"Level1": "3",
"LevelCategory": "This includes all meats, seafood and poultry. We recommend organic sources here. Eggs (with and without yolk) are also in this section.",
"LevelID": "1275a833-b250-4de0-b29a-0b926e57bff0",
"LevelName": "Proteins"
}
使用JSON数据检查滑块值并获得正确级别类别、名称等的最佳方法是什么
现在,我使用IF作为滑块值。有更好的方法吗?最好使用字典,将数值编码为键,将所需的相应信息(可能是自定义结构)编码为值。这样,就可以直接从滑块值到信息进行简单的查找