Professional Documents
Culture Documents
Animesh Mishra
May 6, 2018 · 4 min read
https://medium.com/@anios4991/ios-interview-questions-swift-part-3-c0e326bd2e66 1/6
22.09.2019 iOS Interview Questions (Swift) — Part 3 - Animesh Mishra - Medium
They are almost the same as functions but don’t necessarily have a name.
No need to declare the type of each parameter, if you do so you don’t need to state
the return type of the closure.
When you are passing a closure in function’s arguments, using it before the
function’s body gets execute and returns the compiler back.
When the function ends, the passed closure goes out of scope and have no more
existence in memory.
@escaping closures: .
When are passing the closure in function’s arguments, using it after the function’s
body gets execute and returns the compiler back.
When the function ends, the scope of the passed closure exist and have
existence in memory, till the closure gets executed. link
Arrays — are used to store same type of multiple values in ordered manner.
Sets — are used to store same type of distinct values in unordered manner.
https://medium.com/@anios4991/ios-interview-questions-swift-part-3-c0e326bd2e66 2/6
22.09.2019 iOS Interview Questions (Swift) — Part 3 - Animesh Mishra - Medium
For example, if you create a custom class to open a file and write some data to it, you
might need to close the file before the class instance is deallocated.
De-initializer is written without any parenthesis, and it does not take any parameters.
deinit {
// perform the deinitialization
}
The expression a is always of an optional type. The expression b must match the
type that is stored inside a.
https://medium.com/@anios4991/ios-interview-questions-swift-part-3-c0e326bd2e66 3/6
22.09.2019 iOS Interview Questions (Swift) — Part 3 - Animesh Mishra - Medium
1. When working with optional values, you can write ‘?’ before operations like methods,
properties, and subscript.
2. If the value before the ‘?’ is nil, everything after the ‘?’ is ignored and the value of the
whole expression is nil.
3. Otherwise, the optional value is unwrapped, and everything after the ‘?’ acts on the
unwrapped value.
“!” Mark
1. Once you’re sure that the optional does contain a value, you can access its underlying
value by adding an exclamation mark (!) to the end of the optional’s name.
2. The exclamation mark effectively says, “I know that this optional definitely has a value;
please use it.”
3. Only use in case when you are absolutely certain that the implicitly unwrapped optional
has a value when it is first accessed.
In Swift, you can use typealias for most types. They can be either:
https://medium.com/@anios4991/ios-interview-questions-swift-part-3-c0e326bd2e66 4/6
22.09.2019 iOS Interview Questions (Swift) — Part 3 - Animesh Mishra - Medium
Function — is declared in the global scope and doesn’t belong to any type.
Sometimes it’s useful to name each parameter when you call a function, to indicate the
purpose of each argument you pass to the function.
If you want users of your function to provide parameter names when they call your
function, define an external parameter name for each parameter, in addition to the local
parameter name.
For previous parts follow the link Part1 & Part2..All About Closure & All
About Properties
https://medium.com/@anios4991/ios-interview-questions-swift-part-3-c0e326bd2e66 6/6