StackOverflowFeed
Simple app that show feed with questions from StackOverflow, using Stack Exchange API
I've Used the MVVM design pattern because I think it's a much better design than MVC, where we get huge controllers with too much responsibility. I think that Controllers should be simple and dumb as possible. In the code you will be able to see i kept all logic in the view models + i'm always thinking how can I decouple my viewmodels as much as possible from each other. In order to achieve decoupling I used: dependency injection, delegates and completion closure.
To fetch Data I used https://api.stackexchange.com/, in the app user can choose through Segment controller if he want to see all questions regardless of their state (Answered / Unanswered), only Answered questions and only questions with no answers. App will fetch the most recent questions. I've created 3 different filter to achieve this:
- All Questions filter - //https://api.stackexchange.com/docs/questions#order=desc&sort=creation&filter=!)riR7ZAnq.5)aew*O3KM&site=stackoverflow
- Questions with answers only filter - //https://api.stackexchange.com/docs/answers#order=desc&sort=creation&filter=!)qTDdy7U-SEfPyH_LCqS&site=stackoverflow
- Questions with no answers filter - // https://api.stackexchange.com/docs/no-answer-questions#order=desc&sort=creation&filter=!0WJ3YL7_.Gx8.pOU_QDEKuri2&site=stackoverflow
Refresh: I Used tableViewController.refreshControl to refresh the table. Users can refresh by swiping the table down from the top. (as on Instagram app)
Paradigms: Requests for the next page with new models will take place when the last cell of the table view will be displayed.
I've encountered few problems during building the App:
-
Problem: In the Task I've been asked to filter with Answers/noAnswer but the api does not provide an endpoint for questions with answers (https://api.stackexchange.com/docs). Solution: I've queried a filter for answers. When user click on specific question i'm building the link for the question from the model.question_id
-
Problem: When app first launch when I tried to fetch data on viewDidLoad(), fetching data taking to long and TableView show empty for 1-2 seconds until data is retrieve and table is refreshed Solution: From what I was taught and experienced Singletons are bad practice for most of the time. I usually tried to avoid them as much as possible. But, in this scenario i made the QuestionsManager a Singleton so i can init him and fetch the models for the first View user's interact with, on the Success callback I changed the root window viewcontroller, then I passed to Datasource.setup() the StackOverflowQuestionsManager.shared as a "dependency injected". However I would rather think of some better design than use a singleton here. So to conclude, in SceneDelegate I'm changing the window?.rootViewController to be the LaunchScreen and fetching first models (All questions as it by default the first screen) in the completion handler i'm changing the window?.rootViewController to be the rootviewcontroller of the main storyboard. That way I'm making sure the QuestionsManager singleton object has models to show when building table views.
-
Problem: Load the WKWebView before showing the webview: Solution: I've added a UIActivityIndicatorView for better UX. Can be approved in my honest opinion.