Is there any disadvantage in terms if performance or something by marking a variable as a private on a class or struct on Swift or view on SwiftUI?
I know about the encapsulation advantage you get when the variable is private, preventing access from other code outside the scope. My concern is about performance.
CodePudding user response:
I can say (Flutter experience) it won't slow down your code or app. Its just usable from this one file... but you mentioned that earlier in your question.
But no this won't make your app slower.
CodePudding user response:
Swift is usually a compiled language (interpreters may exist but they are definitely not common) and once the source code is compiled (which is not something the end user will have to sit through, anyway), there is no performance increase or decrease caused by access control. In fact, after the code has been compiled, there is no such thing as access control--the process is now represented as machine code and it will simply run the way it was written to run. Access control is there for the programmer, not the machine. And in terms of compilation performance, I've yet to come across any literature to suggest a compiler will perform better or worse because of access control.