help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
swift-ios-calculator
RSK World
swift-ios-calculator
Swift iOS Calculator v1.0 - AI Math Solver + 3D Graphing + Apple Watch Integration + iOS Widgets + Siri Shortcuts + Currency Converter + Scientific Calculator + Matrix Operations + Platform Integration + Modern iOS Development
swift-ios-calculator
  • Assets.xcassets
  • Base.lproj
  • swift-ios-calculator.xcodeproj
  • AIMathSolverViewController.swift26.6 KB
  • AppDelegate.swift1.7 KB
  • CalculatorHistoryViewController.swift6.5 KB
  • CalculatorLogic.swift4.4 KB
  • CalculatorSettingsViewController.swift5.6 KB
  • CalculatorTheme.swift8.3 KB
  • CalculatorUtils.swift6.9 KB
  • CalculatorViewController.swift3.4 KB
  • CalculatorWidget.swift14.3 KB
  • CalculatorWidgetInfo.plist846 B
  • ChemistryCalculatorViewController.swift26.9 KB
  • CurrencyConverterViewController.swift13.3 KB
  • CustomFormulaBuilderViewController.swift22.1 KB
  • EngineeringCalculatorViewController.swift25.7 KB
  • EquationSolverViewController.swift22.8 KB
  • FinancialCalculatorViewController.swift27.5 KB
  • GeometryCalculatorViewController.swift29.7 KB
  • Graphing3DViewController.swift20.8 KB
  • GraphingCalculatorViewController.swift14.7 KB
  • Info.plist3.2 KB
  • LICENSE1.1 KB
  • MainTabBarController.swift22.3 KB
  • MatrixCalculatorViewController.swift26.6 KB
  • PRIVACY_POLICY.md1.6 KB
  • PhysicsCalculatorService.swift8.2 KB
  • ProgrammerCalculatorViewController.swift11 KB
  • README.md8.7 KB
  • RELEASE_NOTES.md6.5 KB
  • SceneDelegate.swift2.8 KB
  • ScientificCalculatorViewController.swift6.2 KB
  • SiriShortcutsManager.swift23.5 KB
  • Swift iOS Calculator.entitlements1.1 KB
  • UnitConverterViewController.swift14 KB
  • WatchCalculatorViewController.swift15.3 KB
  • index.html47.5 KB
ScientificCalculatorViewController.swift
ScientificCalculatorViewController.swift
Raw Download
Find: Go to:
//
//  ScientificCalculatorViewController.swift
//  Swift iOS Calculator
//
//  Created by RSK World on 23/01/2026.
//  Copyright © 2026 RSK World. All rights reserved.
//
//  Developer: Molla Samser (Founder, RSK World)
//  Designer & Tester: Rima Khatun
//  Contact: info@rskworld.com, +91 93305 39277
//  Website: https://rskworld.in
//  Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India - 713147
//

import UIKit

class ScientificCalculatorViewController: UIViewController {
    
    // MARK: - Outlets
    @IBOutlet weak var displayLabel: UILabel!
    @IBOutlet weak var secondaryDisplayLabel: UILabel!
    
    // MARK: - Properties
    private var calculator = CalculatorLogic()
    private var isUserTyping = false
    private var isScientificMode = false
    
    // MARK: - Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    // MARK: - UI Setup
    private func setupUI() {
        displayLabel.text = "0"
        displayLabel.font = UIFont.systemFont(ofSize: 42, weight: .light)
        displayLabel.textAlignment = .right
        displayLabel.textColor = .label
        
        secondaryDisplayLabel.text = ""
        secondaryDisplayLabel.font = UIFont.systemFont(ofSize: 18, weight: .regular)
        secondaryDisplayLabel.textAlignment = .right
        secondaryDisplayLabel.textColor = .secondaryLabel
    }
    
    // MARK: - Basic Number Actions
    @IBAction func numberButtonPressed(_ sender: UIButton) {
        guard let number = sender.currentTitle else { return }
        
        if isUserTyping {
            if displayLabel.text != "0" {
                displayLabel.text?.append(number)
            } else {
                displayLabel.text = number
            }
        } else {
            displayLabel.text = number
            isUserTyping = true
        }
    }
    
    @IBAction func operationButtonPressed(_ sender: UIButton) {
        guard let operation = sender.currentTitle else { return }
        
        if isUserTyping {
            calculator.setNumber(displayLabel.text ?? "0")
            isUserTyping = false
        }
        
        updateSecondaryDisplay(operation)
        
        if let result = calculator.calculate(symbol: operation) {
            displayLabel.text = formatNumber(result)
        } else {
            displayLabel.text = "Error"
        }
    }
    
    @IBAction func clearButtonPressed(_ sender: UIButton) {
        displayLabel.text = "0"
        secondaryDisplayLabel.text = ""
        isUserTyping = false
        calculator.clear()
    }
    
    @IBAction func decimalButtonPressed(_ sender: UIButton) {
        if isUserTyping && !(displayLabel.text?.contains(".") ?? true) {
            displayLabel.text?.append(".")
        } else if !isUserTyping {
            displayLabel.text = "0."
            isUserTyping = true
        }
    }
    
    @IBAction func plusMinusButtonPressed(_ sender: UIButton) {
        guard let currentText = displayLabel.text, currentText != "0" else { return }
        
        if currentText.hasPrefix("-") {
            displayLabel.text = String(currentText.dropFirst())
        } else {
            displayLabel.text = "-" + currentText
        }
    }
    
    @IBAction func percentageButtonPressed(_ sender: UIButton) {
        guard let currentText = displayLabel.text,
              let number = Double(currentText) else { return }
        
        let result = number / 100
        displayLabel.text = formatNumber(result)
        isUserTyping = false
    }
    
    // MARK: - Scientific Function Actions
    @IBAction func scientificFunctionPressed(_ sender: UIButton) {
        guard let function = sender.currentTitle else { return }
        
        if isUserTyping {
            calculator.setNumber(displayLabel.text ?? "0")
            isUserTyping = false
        }
        
        updateSecondaryDisplay(function)
        
        if let result = calculator.performScientificOperation(function) {
            displayLabel.text = formatNumber(result)
        } else {
            displayLabel.text = "Error"
        }
    }
    
    @IBAction func memoryFunctionPressed(_ sender: UIButton) {
        guard let memoryFunction = sender.currentTitle else { return }
        
        switch memoryFunction {
        case "MC":
            calculator.memoryClear()
        case "MR":
            if let memoryValue = calculator.memoryRecall() {
                displayLabel.text = formatNumber(memoryValue)
                isUserTyping = false
            }
        case "M+":
            if let currentText = displayLabel.text, let number = Double(currentText) {
                calculator.memoryAdd(number)
            }
        case "M-":
            if let currentText = displayLabel.text, let number = Double(currentText) {
                calculator.memorySubtract(number)
            }
        default:
            break
        }
    }
    
    @IBAction func constantButtonPressed(_ sender: UIButton) {
        guard let constant = sender.currentTitle else { return }
        
        switch constant {
        case "π":
            displayLabel.text = formatNumber(.pi)
            isUserTyping = false
        case "e":
            displayLabel.text = formatNumber(.e)
            isUserTyping = false
        default:
            break
        }
    }
    
    // MARK: - Helper Methods
    private func formatNumber(_ number: Double) -> String {
        if number.isNaN || number.isInfinite {
            return "Error"
        }
        
        if number.truncatingRemainder(dividingBy: 1) == 0 {
            return String(Int(number))
        } else {
            return String(number)
        }
    }
    
    private func updateSecondaryDisplay(_ operation: String) {
        if let currentText = displayLabel.text {
            secondaryDisplayLabel.text = "\(currentText) \(operation)"
        }
    }
    
    // MARK: - Mode Toggle
    @IBAction func toggleCalculatorMode(_ sender: UIButton) {
        isScientificMode.toggle()
        // Update UI to show/hide scientific buttons
        // This would typically involve showing/hiding constraints or views
    }
}
198 lines•6.2 KB
swift

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer