Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🔗 Swift Basics: Optional Chaining

A concise, runnable playground demonstrating optional chaining in Swift.

Platform iOS Swift Xcode Stars Last Commit

📖 Overview

Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the call succeeds; if it is nil, the whole expression evaluates to nil instead of crashing.

This repository is a concise, runnable Swift playground learning example. It shows how the ? operator lets you safely reach into a chained call and gracefully unwrap the result.

📝 What it covers

  • Using the optional-chaining operator (?) after a call that returns an optional
  • Chaining firstIndex(of:) on an array with .description and .uppercased() in a single expression
  • How the entire expression short-circuits to nil when the value is absent
  • Producing a safely unwrapped optional String result without force unwrapping
let optionalChainingArray = ["Ahmet", "Alex", "Marcus", "Marie", "Natalie", "Ayla", "Marcus"]
let object = optionalChainingArray.firstIndex(of: "Marcus")?.description.uppercased()

🚀 Getting Started

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

Unzip OptionalChaining.playground.zip, open OptionalChaining.playground in Xcode, and run it to see the results appear inline.

📋 Requirements

  • Xcode 12 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 optional chaining (the ? operator)

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors