iOS

Swift Basics

Variables & constants, types, optionals, closures, control flow, error handling

25 domande da colloquioยท
Junior
1

What is the difference between 'let' and 'var' in Swift?

Risposta

let declares an immutable constant while var declares a mutable variable. A constant cannot be changed after declaration, but a variable can change value. Use let by default for safety and code clarity.

2

Which data type is used to represent true or false in Swift?

Risposta

The Bool type is used for boolean values true and false. It is a fundamental type in Swift used in conditionals to control execution flow. Other types serve different purposes: Int for integers, String for text, Boolean does not exist in Swift.

3

What is type inference in Swift?

Risposta

Type inference allows Swift to automatically deduce a variable's type from its initial value. For example, if you assign 42, Swift infers Int. If you assign text, Swift infers String. This makes code concise without losing type safety. You can annotate explicitly if needed.

4

What is an optional in Swift?

5

How do you safely unwrap an optional using 'if let'?

+22 domande da colloquio

Padroneggia iOS per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis