Вопрос

I'm working now on my first really big app to a client. This app will have a server communication and data download/upload.

I want to create a good server communication design at the beginning so i wouldn't have to change it a lot when it hits some problems.

My question is about NSURLSession. As i see it i have 3 options:

1 - Create a serverCommunicator helper class that will managed all of the server traffic

2 - Do all the communication with the server from the viewController itself

3 - Create a helper class only to create the session task, and in the viewController use that task with a completion handler to manage the returned data

What would be the better Design? if there is another option or a helper class you know please let e know..

Thanks,

Это было полезно?

Решение

It's a bit opinion based, but:

I'd use a data controller class. My view controllers would know nothing about the difference between local / remote data. Everything about data access would be controlled by the data controller and the interface it provides would always be asynchronous capable (using callback blocks).

I'd drop NSURLSession and use RestKit (which doesn't support NSURLSession yes, support is work-in-progress) because it makes mapping the external data model into your internal data model very easy. If I did need to use NSURLSession for something, fine, but I'd make that usage explicit only for that activity.

My data controller would own the Core Data stack (though RestKit would create the stack) and mediate access to it. The data controller would also be a singleton. The data controller is the only class that knows about the external data model (though some of the internal data model classes may contain validation logic used during the conversion from external -> internal).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top