P
P
Petrushka2016-09-08 20:39:39
Objective-C
Petrushka, 2016-09-08 20:39:39

How to write for an MVP?

Hello everyone, I want to write a typical application with good MVP code.
I will describe how the application works, along the way asking questions, please, what is wrong, what to fix and how to make it better
The application goes to the server, receives a list of friends, adds them to KorData and outputs to table, when you click on the cell, it takes the friend's ID and passes the ID to another controller And so the FriendsView
view created in xib on which the "Load data" button and the table
lies
add FriendsView to the main view and subscribe to the delegate
1) The user clicks on the button and information about this comes to our VC.
2) VC calls the ServerManager method, which returns an array of FriendServerModel in the block (in which fields like firstName, secondName, userID, userAvatar)
3) Next, VC gives the command to save the FriendServerModel in CorData through the CoreDataManager class method (here I don’t understand how best to pass the FriendServerModel If I pass FriendServerModel right away, it will be stupid that my CoreDataManager knows about FriendServerModel, if I make it parameters, then 100500 parameters will look stupid)
4) After saving to the database, I call the FriendMapper class method in which I pass the FriendCoreDataModel model (which I take from the CoreDataManager, and not from the server, so that the logic does not change for offline) and my FriendMapper does simple logic for converting fields from the server (DB) into the one that we need to display, since doing logic all the time in cells is stupid)
And FriendMapper gives an array of FriendUIModel (in which the avatar, name (firstName + secondName) and no id))
5) VC tells FriendsView, update the table with data and pass the array with FriendUIModel

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
ManWithBear, 2016-09-09
@ManWithBear

You need to decide on the "source of truth."
In the case when the application is essentially a thin client with a cache layer in the form of its own data base, we usually make the server this source.
Then the application model looks something like this:
Server -> Server entities -> Data base entities -> Data base -> Screens
Accordingly, all data changes occur only as a response from the server. Clicked on the "add as a friend" button? I sent a request to the server, in the response I received an updated essence of the list of friends, the date base was updated, the views received a notification about the data update, and were redrawn.
By the way, you can not strain yourself about using NSManagedObject descendants to configure views,

L
lem_prod, 2016-09-09
@lem_prod

I will not comment on exactly your description of the implementation of the pattern, I personally have to click on this in order to present the connections.
And about "write a typical application with good MVP code", I would advise you to just take any MVP framework, understand the architecture, and implement it yourself ... unless of course you want to build a "bicycle")

B
briahas, 2016-10-20
@briahas

Your request " what is wrong, what to fix and how to do better " is very general. If you don’t like everything at all, then don’t do it through MVP. Because - "edit" and "make better" everything is possible.
Specify the moments in which you need help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question