Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    ios – Verbose Swift code, looking for advice on simplifying and improving

    February 16, 2026

    How Cisco Transforms AI Data Centers

    February 16, 2026

    AT&T reveals its iPhone 16 deals — get up to $1,000 off with an eligible trade-in

    February 16, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – Verbose Swift code, looking for advice on simplifying and improving
    iOS Development

    ios – Verbose Swift code, looking for advice on simplifying and improving

    big tee tech hubBy big tee tech hubFebruary 16, 2026002 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – Verbose Swift code, looking for advice on simplifying and improving
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I’m currently working my way through Paul Hudson’s 100 Days of SwiftUI.

    On Day 19, there’s a challenge to create a unit conversion app.

    I’ve cobbled something together and it works but it almost certainly can be improved and in the name of learning I’d love to know how. Any help would be gratefully received.

        let units = ["Celsius", "Fahrenheit", "Kelvin"]
        @State private var fromUnit = "Celsius"
        @State private var toUnit = "Fahrenheit"
        @State private var inputValue = 0.0
        @FocusState private var entryIsFocused: Bool
        
        var resultValue: String {
            
            var endUnit: String {
                var resultUnits = String()
                if toUnit == "Fahrenheit" {
                    resultUnits = "°F"
                } else if toUnit == "Kelvin" {
                    resultUnits = " K"
                } else {
                    resultUnits = "°C"
                }
                return resultUnits
            }
            
            var convertingTo = Double()
            
            if fromUnit == toUnit {
                convertingTo = inputValue
            } else {
                var convertingFrom = Double()
                if fromUnit == "Fahrenheit" {
                    convertingFrom = ( inputValue - 32 ) / 1.8
                } else if fromUnit == "Kelvin" {
                    convertingFrom = inputValue - 273.15
                } else {
                    convertingFrom = inputValue
                }
                // The conversion
                if toUnit == "Fahrenheit" {
                    convertingTo = convertingFrom * 1.8 + 32
                } else if toUnit == "Kelvin" {
                    convertingTo = convertingFrom + 273.15
                } else {
                    convertingTo = convertingFrom
                }
            }
            let result = String(format: "%.1f\(endUnit)", convertingTo)
            return result
        }
    



    Source link

    Advice Code improving iOS Simplifying Swift Verbose
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    Fatal ‘Index out of range’ error when using macOS simulator in Xcode but not when using iOS simulator

    February 15, 2026

    ios – How to persist credit balance in a credit-based AI app when using anonymous sign-in?

    February 14, 2026

    Flutter iOS build failing with CocoaPods platform version errors, while Android works fine

    February 13, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    ios – Verbose Swift code, looking for advice on simplifying and improving

    February 16, 2026

    How Cisco Transforms AI Data Centers

    February 16, 2026

    AT&T reveals its iPhone 16 deals — get up to $1,000 off with an eligible trade-in

    February 16, 2026

    TypeScript 6.0 beta lays the foundation for shifting the codebase from JavaScript to Go

    February 15, 2026
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    ios – Verbose Swift code, looking for advice on simplifying and improving

    February 16, 2026

    How Cisco Transforms AI Data Centers

    February 16, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.