Skip to content

RefreshableViewController is simple view controller with state management based on PromiseKit.

License

Notifications You must be signed in to change notification settings

dclelland/RefreshableViewController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RefreshableViewController

RefreshableViewController is simple view controller with refreshable state management based on PromiseKit.

Example usage:

import UIKit
import PromiseKit
import RefreshableViewController

struct APIClient {
    
    static func getItem(itemID: Int) -> Promise<Item> {
        return Promise { fulfill, reject in
            // Make HTTP requests, etc...
            let item = Item(name: "Item Name")
            fulfill(item)
        }
    }
    
}

struct Item {

    let name: String
    
}

class ItemViewController: RefreshableViewController<Item> {
    
    convenience init(itemID: Int) {
        self.init(request: APIClient.getItem(itemID: itemID))
    }
    
    override func refreshState() {
        super.refreshState()
        
        switch state {
        case .ready:
            print("View controller is ready")
        case .loading:
            print("View controller is loading")
        case .success(let item):
            print("View controller loaded item with name: \(item.name)")
        case .failure(let error):
            print("View controller failed to load item with error: \(error)")
        }
    }

}

About

RefreshableViewController is simple view controller with state management based on PromiseKit.

Resources

License

Stars

Watchers

Forks

Packages

No packages published