HomeiOS Developmentios - VIP (clear swift) structure implementation for sequential actions?

ios – VIP (clear swift) structure implementation for sequential actions?


In VIP (Clear structure) you could have View (or ViewController), Interactor and Presenter lessons and the widespread case is View calls Interactor, Interactor calls Presenter and Presenter calls View. Took an instance from right here

The issue is that they describe solely this the most straightforward instance with single VIP loop. However what to do if I want for instance to name a sequence of actions:

  1. test click on depend and present interstitial advert (if an advert counter
    reached some worth)
  2. pop a component from array and push view controller (instantly or
    after interstitial)
  3. if view controller is closed and array is empty then request new components from server and replace display

Instance in MVC:

class SomeViewController: UIViewController {
    var adCounter: Int!
    var adInterval: Int!
    var information: [Any]!
    
    func handleClick() {
        var codeBlock = {
            let dataObj = self.information.popLast()!
            self.showNextScreen(dataObj: dataObj) {
                if self.information.isEmpty {
                    self.fetchData { information in
                        self.information = information
                    }
                }
            }
        }
        adCounter += 1
        if adCounter % adInterval == 0 {
            showAd(completion: codeBlock)
        } else {
            codeBlock()
        }
    }
    
    func showAd(completion: (() -> ())?) {
        //...
    }
    
    func showNextScreen(dataObj: Any, completion: (() -> ())?) {
        //...
    }
    
    func fetchData(completion: (([Any]) -> ())?) {
        //...
    }
}

Easy methods to implement it in VIP? I perceive that I must sequentially name 3 VIP loops however what to move as params? Easy information, completion blocks, delegates or one thing else?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments