Last active
November 15, 2022 08:52
-
-
Save NaStillmatic/9ee726956d2a02da16f4be7e4716351d to your computer and use it in GitHub Desktop.
[Swift] NetworkManager Tutorial with a Singleton Class
This file contains hidden or 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: "") | |
} | |
class NetworkManager { | |
private static var sharedNetworkManager: NetworkManager = { | |
let networkManager = NetworkManager(baseURL: API.baseURL!) | |
return networkManager | |
}() | |
let baseURL: URL | |
private init(baseURL: URL) { | |
self.baseURL = baseURL | |
} | |
class func shared() -> NetworkManager { | |
return sharedNetworkManager | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment