Created
May 28, 2017 09:20
-
-
Save bartjacobs/5b8dcee0d834310a0b5e255c12050d6e to your computer and use it in GitHub Desktop.
What Is a Singleton and How To Create One In Swift (https://cocoacasts.com/what-is-a-singleton-and-how-to-create-one-in-swift/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum API { | |
static let baseURL = URL(string: "https://cocoacasts.com")! | |
} | |
class NetworkManager { | |
// MARK: - Properties | |
private static var sharedNetworkManager: NetworkManager = { | |
let networkManager = NetworkManager(baseURL: API.baseURL) | |
// Configuration | |
// ... | |
return networkManager | |
}() | |
// MARK: - | |
let baseURL: URL | |
// Initialization | |
private init(baseURL: URL) { | |
self.baseURL = baseURL | |
} | |
// MARK: - Accessors | |
class func shared() -> NetworkManager { | |
return sharedNetworkManager | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment