SwiftCalc is a modern and elegant calculator app built with SwiftUI. This app provides basic arithmetic operations in a clean, user-friendly interface, and includes features such as percentage calculations and sign inversion.
- Basic Arithmetic Operations: Perform addition, subtraction, multiplication, and division.
- Percentage Calculation: Easily convert numbers to percentages.
- Sign Inversion: Toggle the sign of numbers.
- Clear Function: Quickly reset the calculator.
- Decimal Support: Handle decimal numbers in calculations.
- User-friendly UI: A clean and intuitive interface designed with SwiftUI.
- Responsive Design: Optimized for both iPhone and iPad screens.
- Swift: The programming language used to build the app.
- SwiftUI: A framework for building the user interface.
- AC: Clears all inputs and resets the calculator.
- +/-: Inverts the sign of the current input number.
- %: Converts the current input number to a percentage.
- Arithmetic Operators (/ x - +): Sets the operation and prepares for the next input.
- =: Calculates the result based on the current operation and inputs.
- Decimal Point: Allows for decimal number input.
- Number Buttons: Appends the pressed number to the current input.
- First Number Storage: Stores the first number when an operation button is pressed.
- Second Number Storage: Stores the second number when the equals button is pressed.
- Operation Handling: Performs the arithmetic operation when the equals button is pressed and displays the result.
ContentView.swift
: The main SwiftUI view containing the user interface and logic.buttonPressed(_:)
: Handles the logic for each button press.calculateResult()
: Performs the calculation based on the current operation and inputs.buttonWidth(_:)
&buttonHeight()
: Calculate the dimensions of the buttons for a responsive design.buttonColor(_:)
: Determines the color of each button based on its function.
- Xcode: Ensure you have Xcode installed on your Mac.
- Clone the repository.
git clone https://github.com/yourusername/swiftcalc.git
- Open the project in Xcode
cd swiftcalc open SwiftCalc.xcodeproj
- Select the target device (iPhone or iPad) in Xcode.
- Click the Run button (or press Cmd+R) to build and run the app on the selected device or simulator.
This project serves as a practical example of building a calculator app using SwiftUI, demonstrating the use of state management, UI design, and basic arithmetic operations in a mobile application. It provides a solid foundation for anyone looking to learn or improve their skills in iOS development with Swift and SwiftUI.
Contributions to this project are welcome. Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License.