iphone - Should I have multiple AFHTTPClients to organize my code -


we're using afnetworking make versioned api requests our mobile app.

in order target specific versions of our api, our app sends special accept header.

i've organized codebase each resource (user, session, image, etc.) has it's own afhttpclient sets accept header upon initialization.

+ (usersapiclient *)sharedclient {     // removed singleton setup code brevity                                                                  // here's version gets set requests pertaining users     __sharedclient = [[usersapiclient alloc] initwithbaseurl:url andversion:2];      return __sharedclient; } 

i set way each request (create user, edit user, user) wouldn't have worry version call; done when specific apiclient created.

this system working great i'm questioning if how should doing this? have 9 objects, that's 18 files (.h, .m) on top of baseapiclient class inherits from.

should of networking code dropped in 1 file, , each request sets appropriate accept header before request made? there significant memory overhead loading 9 different client classes opposed loading 1 giant client class? when designing system thought advantageous create apiclients necessary , on demand. if user opens app , never signs in, never need load code responsible creating session. if of networking code stuffed in 1 file, first time user did requiring http request, networking code loaded memory @ once.

i think main issue clients , never released after instantiation (the singleton retains pointer right?). keep these objects in memory lifetime of app. may harder maintain.

how many versions have? because easy step reduce client per version , not per object, , object call right version.

what though have 1 file that:

  • instantiate client per version during init
  • have methods calls chose right client objects call methods , centralize place handle versions.

also, if it's setting request header, maybe can have 1 client , in calls set right header. don't keep multiple clients instantiated.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -