Swi Interview Questions
Optional pattern: An optional pattern matches items wrapped in an
Optional
enumeration's some(Wrapped) case. Optional patterns
appear in the same places as enumeration case patterns and consist of an
identifier pattern followed by a question mark. An example is given below:
if case let v? = b {
print(v)
}
Guard statement: When certain requirements are not met, the guard statement
in Swi is used to shi program control out of scope. With one key exception,
the guard statement is comparable to the if statement. When a given condition
is met, the if statement is executed. The guard statement, on the other hand, is
executed when a given condition is not met. Example is given below:
guard let v = b else {
return
}
Optional binding: Optional binding is used to determine whether or not an
optional has a value. If it does have a value, unwrap it and save it in a temporary
variable or constant. Example is given below:
if let v = b {
print("b has been unwrapped with success and is = \(v)")
}
Implicitly unwrapped variable declaration: Because a variable may start life as
nil, but will always have a value before you need to use it, implicitly unwrapped
optionals exist. It's helpful not to have to write if let all the time because you
know they'll have value by the time you need them. Example:
var v = b!
Do'stlaringiz bilan baham: