Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Networking in MVVM

Tags:

swift

mvvm

I have an app with MVVM and I don't know where implement networking calls. In ViewModel, in Controller? Another pattern to implement networking?

I think ViewModel is the best place but I'm not totally sure

like image 274
Alvaro Avatar asked Oct 30 '22 04:10

Alvaro


1 Answers

Something like this

// Your network calls
class NetworkQuery {

}

class NetworkCommand {

}

// Service (Facade pattern)
class NetworkServices {

    let networkQuery: NetworkQuery!
    let networkCommand: NetworkCommand!
}

// Your controller or view model, you can place them in either both
class MyControllerOrViewModel {

    let networkServices: NetworkServices!
}

Just now two cents' worth..

like image 176
koropok Avatar answered Nov 15 '22 07:11

koropok