Menu

Swift Explained: Apple's Language for iPhone, Mac, and More
πŸ“°

Swift Explained: Apple's Language for iPhone, Mac, and More

DEV Community: iosΒ·The Practical DeveloperΒ·41 minutes ago
#3b5MPztu
#devtoios#devto#dev#swift#apple
Reading 0:00
15s threshold

Introduction

Swift is Apple's language for its platforms: iPhone, iPad, Mac, Apple Watch, and Apple TV. Introduced in 2014 to replace the older Objective-C, it was designed to be safe, fast, and β€” unusually for a systems language β€” genuinely pleasant to read and write.

Even if you never ship an app, Swift teaches one idea every developer should understand: optionals.

Optionals: saying "this might be missing"

Most bugs in app development come from one cause: code assuming a value exists when it does not. Swift makes that assumption impossible to hide. A value that might be missing is wrapped in an Optional, and you must unwrap it before use.

var nickname : String ? = nil nickname = "Waqas" if let name = nickname { print ( "Hello, \( name ) !" ) } else { print ( "No nickname set." ) }

Enter fullscreen mode

Exit fullscreen mode

String? means "a String, or nothing". The if let unwraps it safely: inside the block, name is guaranteed to exist.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.