Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:45:37+00:00 2026-06-17T13:45:37+00:00

It’s a fairly common scenario for an application to pull data from a server

  • 0

It’s a fairly common scenario for an application to pull data from a server (usually a JSON string). This data is then parsed and converted into native classes like NSString, NSArray, NSDictionary, etc.

Most of the time, however, we want to use custom models to represent this remote data.

For example if we’re pulling a JSON array of blog posts we’d want to map those into BlogPost model objects for example:

// BlogPost.h
@interface BlogPost: NSObject
@property NSString *title;
@property NSString *body;
@property NSDate *dateCreated;
@property NSArray *comments;
@end

What’s your approach for decoupling the “JSON” model from the native model?

I often find myself writing a custom initializer in the model itself which takes a dictionary (which typically comes from the JSON feed).

For example:

// BlogPost.h
+ (BlogPost *)blogPostWithJSON:(NSDictionary *)jsonDictionary;

Then I have to keep track of the keys used on the server and map those to my properties.

I always feel a little uneasy doing this because the model in the application shouldn’t really have to know what keys are used on the server.

Should I instead move this JSON-to-Object mapping in another class? Perhaps a Factory? Or should my network manager be creating and returning ready made objects to me directly?

Perhaps something like:

// NetworkManager.h
- (void)getBlogPostWithCompletion:(void (^)(BlogPost *blogPost))completionBlock;

(Of course I’m omitting lots of details here like which blog post to get but it’s just to demonstrate an approach).

Any other approaches? How do you decouple your server data from your local models?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:45:38+00:00Added an answer on June 17, 2026 at 1:45 pm

    I have faced this problem a couple of times and got pretty much the same questions as you. In the end what I find works for me is:

    • Create an OO representation of the original model. In your case this would mean decoding the JSON array into whatever it uses as an underlying model (a dictionary?). Depending on how is modeled the service that you are using, you may end up with some “record classes” (i.e. classes without behavior). I generally prefer to have these type of classes instead of arrays or dictionaries, since as your software evolves this allows to add behavior to them if you need. If, on the other hand, you use arrays or dictionaries you can’t do that.
    • Once you have a low-level OO model, create an OO domain model. In this new model you design things as your domain requires and not tied to the service provider’s model. Many times you will find a 1 to 1 mapping between your domain classes and the provider’s one, but that is not mandatory. The point here is that you should abstract your domain and design it as you feel is right.

    The mapping between this two models can be done in different ways, according to its complexity. I generally like to pick one of these three approaches and stick to it in order to have an homogeneous approach in the project:

    1. Write a class method (class)HighLevelObject>>from(aLowLevelObject) in your domain model. This takes a low level object and configures itself. You do this for all your high-level objects that have a low-level counterpart.
    2. The opposite to the previous one: write an instance method LowLevelObject>>createHighLevelObject() in the low level object that creates an instance of your domain model. Here you a re shifting the responsibility of creating a new object to the lower layer.
    3. Create a factory or builder (depending on the complexities of your models) that takes care of the whole creation process.

    If you have simple models with many 1 to 1 mappings between them I would go for options 1 or 2. Which one to choose depends pretty much on your tastes; the option 1) has the advantage that the object knows how to construct itself but places the transformation process burden in the domain model. The second approach leaves a “cleaner” domain model, but forces the lower layer to know the details of the upper one and may force you to break encapsulation. I don’t think that there is a silver bullet here; IMHO you should choose the approach that best fits your needs and programming tastes.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using jsonparser to parse data and images obtained from json response. When
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.