Daily iOS
Swift

private vs fileprivate

In one file you have class A { fileprivate func secret() {} } and class B. Can B call A().secret(), and what changes if you switch it to private?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

fileprivate is accessible anywhere in the same file, so B can call it. private is limited to the enclosing type's scope, so B can't.

Share a question