Swi Interview Questions
class Human: Equatable {
let id: Int
let nameOfPerson: String
init(id: Int, nameOfPerson: String) {
self.id = id
self.nameOfPerson = nameOfPerson
}
static func == (left: Human, right: Human) -> Bool {
return left.id == right.id
}
}
let human1 = Human(id: 2, nameOfPerson: "Janvi")
let human2 = Human(id: 2, nameOfPerson: "Janvi")
Now, for the piece of code given below, we can say that the two human instances are
equal since their id is the same. Therefore, "Equal Instances!" gets printed.
if human1 == human2 {
print("Equal Instances!")
}else{
print("Instances Not Equal!")
}
Now, for the piece of code given below, we can say that the two human instances are
not equivalent even though their id is the same since they point to different areas in
the Heap Area, that is, they point to different addresses. Therefore, "Instances are
not Equivalent!" gets printed.
if human1 === human2 {
print("Equivalent Instances!")
}else{
print("Instances are not Equivalent!")
}
5. Throw light on some of the differences between Swi and
Objective C.
Some of the differences between ios Swi and Objective C are as follows:
Page 10
© Copyright by Interviewbit
Swi Interview Questions
Comparison Parameter
ios Swi
Objective C
Type of Programming
Language.
ios Swi is an
object-
oriented and
functional
programming
language.
Objective C is
a class-based
object-
oriented
programming
language.
Dynamic Libraries
Dynamic
Libraries are
supported by
ios Swi . For
instance,
system iOS
and macOS
libraries are
dynamic. In
other words,
these
applications
will receive
improvements
from Apple’s
updates
without new
build
submission.
Dynamic
Libraries are
not
supported by
Objective C.
Do'stlaringiz bilan baham: |