Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does guard make a copy of variables in swift

In swift you can unwrap optional values with a guard statement

guard let foo = foo else { return nil }

Is this statement making a copy of foo? In other words, could this statement be potentially expensive if foo is very large?

like image 858
Devin Haslam Avatar asked Oct 20 '25 05:10

Devin Haslam


1 Answers

Actually this depends on type of foo e.x class type won't create a copy unlike struct type

guard isn't a magic keyword it simply if not presented in 1 word

like image 81
Sh_Khan Avatar answered Oct 22 '25 20:10

Sh_Khan