Skip to content

ahmetbostanciklioglu/FailableInitialize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🧩 Swift Basics: Failable Initializers

A concise, runnable Swift Playground exploring initializers that can return nil.

Platform iOS Swift Playground Stars Last Commit

πŸ“– Overview

A failable initializer (init?) lets a type reject invalid input during construction by returning nil instead of a fully formed instance, which is why a call to it produces an optional. This repository is a small, runnable Xcode Playground that demonstrates the concept with two minimal examples: a custom class that validates its input inside init?, and Swift's built-in failable Bool(_:) string initializer. It is meant as a concise learning reference rather than a full app.

✨ What it covers

  • Declaring a failable initializer with init? on a custom class.
  • Returning nil from an initializer when a validation condition is not met.
  • How a failable initializer produces an optional instance at the call site.
  • Swift's built-in failable Bool(String) initializer, which yields nil for anything other than "true" / "false".

πŸš€ Getting Started

git clone https://github.com/ahmetbostanciklioglu/FailableInitialize.git
cd FailableInitialize
unzip FailableInitialize.playground.zip
open FailableInitialize.playground

Open the .playground in Xcode and press Command-R (or let it run) to see each line evaluate live in the results sidebar.

πŸ“‹ Requirements

  • Xcode 13 or later
  • Swift 5
  • iOS Playground target

πŸ§‘β€πŸ’» 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 Playground demonstrating failable initializers (init?) in Swift

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors