~2s delay after pushViewController on devices with iOS 13

Hi,

I have application in Swift 4 in MVVMC. After iOS 13 release I have problem with ~2s delay after pushViewController method. It is ok on iOS 11, 12. I've checked build created on xcode 10.3 and 11.2.1 and in both of them there is a issue with that delay.

Accepted Reply

After a while I've found that one method with setting label.text callef from viewModel was called from globalQueue from some reasen. That caused that delay. I don't know yet why on iOS 11 and 12 that worked perfectly. I had to call that method from mainQueue and it woked perfectly for me. I'll have to check changes in iOS 13 about GCD.

Replies

Could you show the code where you call pushViewController ?


Do you call it from the main thread ?


Have a look here for some similar problem:

https://stackoverflow.com/questions/25754629/pushviewcontroller-extremely-slow

    func pushSomeViewController(with model: SomeViewModel) {
        let viewModel = OtherViewModel(coordinatorDelegate: self, model: model)
        let viewController = OtherViewController(viewModel: viewModel)
        
        rootViewController.pushViewController(viewController, animated: true)
    }

It is called from main thread. It works perfectly on iOS 11 and 12 but it lags on iOS 13 idk why.
That code is placed in coordinator and it's called by protocol delegate after collectionViewCell is tapped.

Did you try to replace line ( by :

          DispatchQueue.main.async {
             rootViewController.pushViewController(viewController, animated: true) 
         }

Yes I tried. It doesn't help because it is already called on main thread.

So, it maybe something inside OtherViewModel or OtherViewController that causes delay.

let viewModel = OtherViewModel(coordinatorDelegate: self, model: model)

let viewController = OtherViewController(viewModel: viewModel)


Could you post the code of those 2 class init ?

Try setting the background color of the opushed vc to something non transparent. That should do the trick 😉

Next VC has background color. BTW with white background color issue with transition look a bit different. It would lag animation, in my scenario it works correctly but push action happens after delay.

ViewController init:

    convenience init(viewModel: SomeViewModel) {
        self.init()
        
        self.viewModel = viewModel
        self.viewModel.viewDelegate = self
    }


ViewModel init:

    init(model: SomeRenderable, coordinatorDelegate: SomeCoordinatorDelegate?, api: Api = Api()) {
        self.model = model
        self.coordinatorDelegate = coordinatorDelegate
        self.api = api
    }

Thanks, but there is something unclear.


You call :

let viewModel = OtherViewModel(coordinatorDelegate: self, model: model)


but the init signature (if it is the one for OtherViewModel) does not match (first 2 arguments in reverse order)

init(model: SomeRenderable, coordinatorDelegate: SomeCoordinatorDelegate?, api: Api = Api()) {


In addition, could you show API init ?

It's my bad I switched them here by mistake. And API is just base class for networking(Moya) with setup of provider and plugins. I've checked that even after cutting off networking layer from application transition still has delay.

So, you could ask the question to the Moya community, they may have some clue on what's happening there in the networking session.

But it's not Moya foult, like I said I've commented all networking and pushed clear viewController and it still has delay.

Could you show the version of


    func pushSomeViewController(with model: SomeViewModel) {


without any networking ?

func pushSomeViewController(with model: SomeViewModel) {  
        let viewModel = OtherViewModel(coordinatorDelegate: self, model: model)  
        let viewController = OtherViewController(viewModel: viewModel)  
          
        rootViewController.pushViewController(viewController, animated: true)  
    }


That method is called on main thread.

May I check. Is it Swift or SwiftUI ?