Chapter 18 fileprivate

In the section discussing private and fileprivate concerning class CheckAccount, the following statement is made:
“Right now, nothing is preventing a haphazard coder who doesn’t read the documentation from creating a Check on their own. In your safe code, you want a Check to only originate from CheckingAccount so that it can keep track of balances.”

Since Check is local to CheckingAccount, I cant see how a coder can initialize a Check from
outside of CheckingAccount.

Thanks
Sam

You can’t. By right, no one should be able to make a Check without any account tied to them.

Only an instance of CheckingAccount could create a check with its public method writeCheck which returns optional Check.

Fileprivate just means that no other swift files can use the Check’s initializer aside from the file where you declare it.

Hope that answers your question.

This topic was automatically closed after 166 days. New replies are no longer allowed.