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

    Engineering Manager Vs IC: How to Choose With Clarity

    April 22, 2026

    IoT scaling challenges slow deployments at enterprise scale

    April 22, 2026

    National Nanotechnology Day 2025 Activities

    April 22, 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

    swift – How to detect an actual iOS in app purchase in Transaction.updates listener in StoreKit2?

    April 22, 2026

    5 Pieces of Advice for the Leader Inheriting the Mess

    April 22, 2026

    swiftui – How I make quiz in interactive widget for iOS 17 +?

    April 21, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Engineering Manager Vs IC: How to Choose With Clarity

    April 22, 2026

    IoT scaling challenges slow deployments at enterprise scale

    April 22, 2026

    National Nanotechnology Day 2025 Activities

    April 22, 2026

    Amazon expands Anthropic partnership with $25 billion investment

    April 22, 2026
    Timer Code
    15 Second Timer for Articles
    20
    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!

    Engineering Manager Vs IC: How to Choose With Clarity

    April 22, 2026

    IoT scaling challenges slow deployments at enterprise scale

    April 22, 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.