Computer Science, asked by yaswanthb001, 7 months ago

Swift language:
Explain the concept of optional-chaining to print "megaPixel" value of camera by using the following example code only
struct Person {
var name: String
var phone: Phone?
}
struct Phone {
var camera: Camera?
}
struct Camera {
var megaPixel: Int
}

Answers

Answered by Jaskiranjeetkaur
0

sorry too big

omg oh my god

Answered by aanujs2590
1

Answer:

struct Person {

var phone: Phone?

}

struct Phone {

var camera: Camera?

}

struct Camera {

var megaPixel: Int = 40

}

var cand = Person()

cand.phone = Phone()

if let megapixel = cand.phone?.camera?.megaPixel {

print("MexaPixel value is \(megapixel)")

}

else {

print("MegaPixel value of Camerae cannot be retreived")

}

Explanation:

Similar questions