AFHTTPRequestOperationManager property or not in shared client?

I use AFNetworkingfor all my connections in my application. I created a single-user "client" class that runs all the code AFNetworkingand uses AFHTTPRequestOperationManager. Am I confused about whether an object AFHTTPRequestOperationManagershould be a property, or should I recreate it every time my client requests a connection? If this property, can my client be called asynchronously many times, or will it cause problems because the same instance AFHTTPRequestOperationManagerwill be used, possibly at the same time?

+4
source share
1 answer

Typically, your single-user "client" class will be a subclass AFHTTPRequestOperationManager. It may also be a property, but then you cannot override the methods. Some commonly overridden methods:

  • - HTTPRequestOperationWithRequest:success:failure:to change the way all request operations are created (for example, if you need the same header in each request)
  • – initWithBaseURL:to apply advanced settings to the operations manager

However, the property may work fine, depending on your needs. (See Prefer composition over inheritance? For a delightful weekend reading.)

And finally:

If this property, can my client be called asynchronously many times, or will it cause problems because the same instance AFHTTPRequestOperationManagerwill be used, possibly at the same time?

, AFHTTPRequestOperationManager . , . ( , , .)

+4

Source: https://habr.com/ru/post/1523692/


All Articles