swift interview questions for iOS developer: Part 1
swift interview questions and answers for Experience Developer and fresher
1.What is Struct in Swift?
Struct School {
var clothes: String
var shoes: String
}
2. What is Class in swift ?
class School {
var clothes: String
var shoes: String
}
3. What is completion handler in swift ?
4.What is difference between frame and bound ?
5. What is tuple?
func split(name: String) -> (firstName: String, lastName: String) {
let split = name.components(separatedBy: " ")
return (split[0], split[1])
}
6. Whats is higher order function?
7 .What is inheritance?
- class SomeSuperclass {
- // baseclass definition goes here
- }
- class SomeSubclass: SomeSuperclass {
- // subclass definition goes here
- }
- class Fruits {
- var weight = 0.0
- }
- class Mango: Fruits {
- }
- let mango = Mango()
- mango.weight = 215.0
8. What is singleton class in swift ?
SingleTon class is the object which provide single point of access to the function of the class
example:
Class Common {
static let shared = Common()
private init()
func sum()-> Int {
return 10 + 20
}
}
accessing the singleton
let Sum = Common.shared.sum()
print (Sum)
output Sum = 30
9. What are the feature only available in class compare to struct in swift?
* Type Casting : We can check the type of the class in runtime.
* Reference Counting : Allow more than 1 reference to the class instance
* Inheritance : A class can inherit the property or characteristic of other class but in struct we cannot.
* De initialisation : we can de-initialise the class resource at any instant.
10 . What is optional Chaining?
Optional Chaining is the Process of querying and calling the properties with an optional that may be nil
let object = {}
object?.data = 1