Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

🏗️ Swift Basics: Initializers

A concise, runnable example of how initializers set up Swift structs.

Platform Swift Xcode Stars Last Commit

📖 Overview

Initializers are the special methods that prepare a new instance of a type for use by giving every stored property a starting value. This repository is a short, runnable learning example that walks through the different ways a Swift struct can be initialized — from the free memberwise initializer to custom init() methods and initializers added through extensions.

✨ What it covers

  • Memberwise initializers — the automatic initializer a struct gets for free based on its stored properties.
  • Custom initializers — writing your own init() to assign values and run setup logic such as a print.
  • Default property values — how a default makes the matching argument optional at the call site.
  • Using self — disambiguating a stored property from a parameter inside an initializer.
  • Initializers in extensions — adding an init() in an extension so the synthesized memberwise initializer is kept alongside it.

🚀 Getting Started

git clone https://github.com/ahmetbostanciklioglu/Initializers.git
cd Initializers

Paste the snippet from README.md into an Xcode Playground (or a .swift file) and run it to watch each initializer create its instance.

📋 Requirements

  • Swift 5+
  • Xcode 12 or later (an Xcode Playground is enough)

🧑‍💻 Author

Ahmet Bostancıklıoğlu@ahmetbostanciklioglu · ahmetbostancikli@gmail.com

⭐ If this helped you, consider giving the repo a star!

About

A concise, runnable Swift example demonstrating struct initializers, memberwise init, custom init, and extensions.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors