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.
![Screenshot 2024-06-18 at 1 35 13 PM](https://private-user-images.githubusercontent.com/81951239/340792356-41e1f8a2-56f2-47d1-bc8c-3201b477e570.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNTc3MjAsIm5iZiI6MTcyMTI1NzQyMCwicGF0aCI6Ii84MTk1MTIzOS8zNDA3OTIzNTYtNDFlMWY4YTItNTZmMi00N2QxLWJjOGMtMzIwMWI0NzdlNTcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDIzMDM0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAwYjBlZGQ2Yjg4YjM3OGEyMmFhOTYzZGY2OGNhY2FmODI2MWIzNjdiNDIyOGVlY2FkZTBmZDg5NjQ2OWYxYWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.LXD2fGHArcgIK9kfb0bsE2Y9hZJtE4PtSuc_JRPsDuE)
![Screenshot 2024-06-18 at 1 35 00 PM](https://private-user-images.githubusercontent.com/81951239/340792397-b685c0a6-4624-4997-96c2-ca557846f06e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNTc3MjAsIm5iZiI6MTcyMTI1NzQyMCwicGF0aCI6Ii84MTk1MTIzOS8zNDA3OTIzOTctYjY4NWMwYTYtNDYyNC00OTk3LTk2YzItY2E1NTc4NDZmMDZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDIzMDM0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg0ZGM1Yzc0NWMzMmVhYmM3MDQyZTUwZDk5YmYwYTgwNzc3YWNmMWY5YzRlYjAzOWMzZTY2ZGZmNmU4M2JkOTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.vU1566E7mtRT_OdQguQs8Ifx0ZxUVeoJLZQTfxQOcJQ)
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.