|
|
# RemoteData
|
|
|
|
|
|
## Init
|
|
|
|
|
|
```swift
|
|
|
let catalogRemoteData = RemoteData(source: Constants.catalogUrl, destination: Catalog.url)
|
|
|
catalogRemoteData.delegate = self
|
|
|
```
|
|
|
|
|
|
## Download
|
|
|
|
|
|
```swift
|
|
|
func downloadCatalog() {
|
|
|
guard !catalogRemoteData.downloading else { return }
|
|
|
|
|
|
if catalogRemoteData.downloaded {
|
|
|
infoLabel.text = "LOADING CATALOG...\n(TAP TO CANCEL)"
|
|
|
} else {
|
|
|
infoLabel.text = "LOADING CATALOG..."
|
|
|
}
|
|
|
|
|
|
progressView.progress = 0
|
|
|
|
|
|
catalogRemoteData.download()
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## RemoteDataDelegate
|
|
|
|
|
|
```swift
|
|
|
func remoteDataDidProgress(progress: Float) {
|
|
|
progressView.progress = progress
|
|
|
}
|
|
|
|
|
|
func remoteDataDidFinish(success: Bool) {
|
|
|
progressView.progress = 0
|
|
|
|
|
|
if success {
|
|
|
infoLabel.text = ""
|
|
|
didLoad()
|
|
|
} else {
|
|
|
infoLabel.text = "ERROR LOADING CATALOG\n(TAP TO TRY AGAIN)"
|
|
|
}
|
|
|
}
|
|
|
``` |