How to change the UITextfield text with data from JSON based on the value from UISlider in Swift 4?

How to change the UITextfield text with data from JSON based on the value from UISlider in Swift 4?

Right now I have the UIText field hard coded and changing according to the value on the UISlider.

Right now I have the UIText field hard coded and changing according to the value on the UISlider.

    @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). "

I was able to connect to the REST api and get the JSON results parsed.

Now, the slider has values from 1 to 6.

The JSON is structured like this:

{
   "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"
}

What's the best way to check the slider value and get the correct Level Category, Name etc. using the JSON data?

Right now, I'm using IF for the slider value. Is there a better way to do this?

ios xcode swift json

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

The ultimate guide to iOS Unit Testing with Swift and Xcode

Unit testing is a testing method where you can test “unit” of code whether it is working as you want or not. In Xcode, use XCTest…

iOS Navigation Controller Tutorial | Xcode 11.4 Swift 5.2

In today's beginner Swift tutorial we discuss the UINavigationController. We talk about what it is, how it works and build a basic version with some customization involving large titles and changing the font color. Doing this can ensure it fits in well with the style of your app.

Hire Dedicated Swift Developers

Want to create a native iOS application for your Startup? **[Hire Dedicated Swift Developers](https://hourlydeveloper.io/hire-dedicated-swift-developer/ "Hire Dedicated Swift Developers")** for end-to-end services like development, migration...

What is JSON - JSON Parsing in Swift

What is JSON and how do you parse JSON in Swift? JSON stands for JavaScript Object Notation and it's a way to represent data in a standard way. Learn how to parse JSON in Swift using the Codable protocol. We take the response JSON data from a real API call and then parse it in Swift!

How To Build Reminders iOS App in Swift 5 for Beginners

In this video, we build the Reminders App in Swift for iOS. Learn how to use dates, local / user notifications, tableviews, and much more. From scratch to working app, we'll go over every step up toe process together.