Welcome to the Swift Practice Codes repository! This project contains a collection of Swift scripts designed to demonstrate and practice core Swift programming concepts. It serves as a personal knowledge base and playground for intermediate Swift topics.
This repository covers various fundamental and intermediate Swift concepts, including:
- Arrays: Initialization, manipulation, subscripting, iteration, and bulk updates.
- Dictionaries: creating and managing key-value pairs.
- Optionals: Handling
nilsafely usingif let,guard, nil-coalescing (??), and forced unwrapping. - Closures: Syntax, capturing values, and passing closures as parameters.
- Higher-Order Functions: Functional programming patterns using
map,filter, andreduce.
Here is a quick guide to the files in this repository:
| Category | File(s) | Description |
|---|---|---|
| Arrays | array0.swift - array4iteration.swift |
Basics of arrays, subscripting, manipulation, and iteration. |
| Dictionaries | dict0.swift |
Basic dictionary operations. |
| Functions | sfunc0reduce.swift, sfunc1filter.swift, sfunc2map.swift |
Examples of higher-order functions (map, filter, reduce). |
| Optionals | optional*.swift, if_let_binding.swift, nilCoalescing.swift |
Techniques for handling optional values safely. |
| Closures | ClosuresInSwift.swift |
Examples of using closures and passing them to functions. |
| Misc | swiftMain.txt |
Learning log and branch planning. |
You can run individual Swift files directly from the terminal.
- macOS with Xcode or Swift installed on your system.
Open your terminal, navigate to the project directory, and run any file using the swift command:
# Navigate to the folder
cd /path/to/VsSwiftTraining
# Run a specific file (e.g., Array Manipulation)
swift array3manuplation.swift
# Run Closure examples
swift ClosuresInSwift.swiftFeel free to add more examples or improve existing ones!
- Fork the repository
- Create a new branch (
git checkout -b feature/new-topic) - Commit your changes
- Push to the branch
- Open a Pull Request
Happy Coding! 🚀