Skip to content

ahmetbostanciklioglu/OptionalChaining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

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

No releases published

Packages

 
 
 

Contributors