قالب وردپرس درنا توس
Home / IOS Development / Why can not I use singleton? Why is this bad design pattern? : iOSProgramming

Why can not I use singleton? Why is this bad design pattern? : iOSProgramming



Hello, I came from the Android world and still feel confused in iOS … The reason is design pattern. For example, one of the coolest and actually preferred by Google way to develop android app uses MVVM + repository. Basically, View ViewModel data, which then provides data to the depot, which then makes network requests and sends back observable. I tried to do something similar in iOS. For example, I have 3 VCS and each sends specific data to the API and after all three VSC sends data (files and other heavy things) I need to make 4-5 network requests. I created a Repository (Singleton) and each viewController (ViewModel) creates network request via Repository.shared.createRequest (data and etc). Then I have dispatchGroup who decides when I have received all the answers and fires my required requests after that. Repository also creates Delegate, which my 4 VC adheres to. In this way, my vibrators only get data and open another viewcontroller instantly, but all responses and logic are handled in the Repository (Singleton) … Why is it bad design pattern? I do not find alternatives. I mean I could make some delegates in my 3 VC and adhere to these delegates in 4 VC (I'll receive an answer) … But in the future this pattern will not scale completely. Please provide actual recomendtations if I will save data that is common to all VCs and should I create network requests? I view model? in Vc? or in singleton?

Sincerely Viktor


Source link