udacity / ios-nd-networking

Resources for Udacity's iOS Networking with Swift course.
MIT License
172 stars 88 forks source link

Use access modifiers for the Auth struct. #4

Open OwenLaRosa opened 5 years ago

OwenLaRosa commented 5 years ago

TMDBClient has an Auth struct that gets modified to store the request token and session ID. These values are only accessed from TMDBClient, but they could be read or modified from another part of the app. This could potentially cause problems for debugging, as it's difficult to know which code modified the Auth values, but currently, there's no safeguard preventing someone from mistakenly modifying them outside of TMDBClient.

To make the intent clearer, you can use Swift's access modifiers to restrict access to the Auth struct, to only TMDBClient.

Haibo-Zhou commented 4 years ago

Well, I try on this.

private static let apiKey = ""

    struct Auth {
        fileprivate static var accountId = 0
        fileprivate static var requestToken = ""
        fileprivate static var sessionId = ""
    }