I watched Stanford 193p, and I had a question.
When the professor writes the code, he writes like this
struct GameView: View {
var body: some View {
gameBody
}
var gameBody: some View {
Button("gameBody") {
gameBodyFunc()
}
}
private func gameBodyFunc() {
}
}
Why is the function declared private but not the gameBody variable?
I am impressed with his coding style and want to learn it.
This is a basic object oriented design/programming thing. Related to design principles of information hiding, encapsulation and modular design.
The idea is to hide all implementation details in the class/struct and only expose minimal public interface to other elements in the software.
Apparently the var members of the struct are used from other structs/classes in the same package, but the private function should be used only by the GameView struct.