0

I have a class called SQLHelper.swift where I have all the methods for fetching records from database, adding records to database and so on.

Then I have another class called Constants.swift where I have some alert messages defined and my API endpoints.

And I call my API’s like so from my viewcontroller…

APIHelper(API: WebServices.getAllData as NSString, json: bodyStr as NSString, methodType: Constants.Get_Method as NSString).PostApiResultSet2(callback: {( errMsg: String,arr11: AnyObject?) -> Void in.....

The WebServices.getAllSchedSmats shown above is from the Constants.swift class that I just mentioned.

There is another class called APIHelper.swift where I have PostApiResultSet2 function which calls the API and returns the response to my view controller

And from my view controller, I access the function from the SQLHelper.swift class whenever I want to perform any db related operations and when I want to make an API call, I access the APIHelper.swift class.

My doubt is I’m not sure which is the architecture I’m using here...

user987654
  • 19
  • 5
  • What is it precisely you want to know "My doubt is I’m not sure which is the architecture I’m using here..." – claude31 Jul 17 '20 at 10:37
  • I meant that with the said ways of making API calls or accessing db, which architectural pattern did I end up using i.e. if its MVC, MVVM etc..? – user987654 Jul 17 '20 at 11:17
  • It is not a pure MVC model. Looks more like MVVM, but a schematics would help clarify if it is a clean MVVM architecture. But the question is a bit theoretical. Question is more: is your design clean enough or a bit over complex ? In addition, I understand that Constants is more than just constants, looks like your Web services API class, isn't it ? – claude31 Jul 17 '20 at 11:25
  • Yes @claude31...my `Constants.swift` class consists both the API endpoints and some other constants... – user987654 Jul 17 '20 at 11:36
  • So is it MVVM..? – user987654 Jul 17 '20 at 11:36
  • Looks closer to MVVM IMHO than to MVC. – claude31 Jul 17 '20 at 11:38
  • have a look here, with detailed explanations and schematics. That should let you check if if you follow correctly a pattern and which it is. https://stackoverflow.com/questions/19444431/what-is-difference-between-mvc-mvp-mvvm-design-pattern-in-terms-of-coding-c-s – claude31 Jul 17 '20 at 11:50
  • Ok ..Thanks @claude31. Also if its MVVM, can you just help me distribute my `Constants.swift`, `APIHelper.swift`, `ViewController.swift` and `SQLHelper.swift` among each of the elemtns of M-V-V-M..? – user987654 Jul 17 '20 at 11:59
  • You know better your components than me… So just try to draw the MVVM architecture (the skematics at the end of the post seem clearer) and check exactly what each objects in your different classes are doing to map them correctly. Starting with View is probably the easiest, because there are few questions about it. Then try to map other objects into ViewModel. Note that you may end up breaking some of the existing classes you defined so far. – claude31 Jul 17 '20 at 12:16
  • Ok @claude31..Thanks... – user987654 Jul 17 '20 at 14:17

0 Answers0