Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between var private(set) and let?

Tags:

ios

swift

iphone

I use an internal library for init objects. This library accepts only var attributes, but I don't want to change var attributes after init. This task is done by declaring attributes as let, but I can`t do that.

As a solution a use private(set) and it works very well.

But, I want to know, is there any difference between var private(set) and let?

Thanks!

like image 708
heming Avatar asked Sep 10 '25 22:09

heming


1 Answers

let stops you from changing the value.

private(set) var stops anything outside of the file from changing the value, while the class itself still has the power to modify it.

like image 155
David Skrundz Avatar answered Sep 12 '25 12:09

David Skrundz