If I force unwrap an optional instance of a struct, does Swift make a copy of it?
For example, in the following code, where Point
is a struct, does Swift copy (internally) point
when I unwrap it?
var point: Point?
point = Point(x: 0, y: 0)
print(point!.x)
Follow-Up Question
If not, then would
if point != nil {
print(point!.x)
}
be more efficient than
if let point = point {
print(point.x)
}
since I assume the latter code (due to the assignment) causes Swift to make a copy of point
, correct??