WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Public var VS var in NSObjectManaged Subclasses

Forums > 100 Days of SwiftUI

When Paul first presents Core Data, he uses public var in the NSObjectManaged Subclasses, but then in his solution to the Friendface - Part2 project he used var instead without public. What's the difference and does it matter? I mean it must matter on some level.


By default, unmarked properties have internal access level. The difference between internal and public is that public properties (and methods) are available across module boundaries, while things marked as internal are not.

It's been quite a while since I looked at any of the HWS projects (although I've been thinking I should redo them now that Paul has updated everything) so I'm not sure why he picked one over the other in the particular case you are asking about.


Thanks. Can you show an example of using one over the other?


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.