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 8682793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:52:07+00:00 2026-06-12T21:52:07+00:00

I am using a iOS library called Restkit, which automatically maps remote objects to

  • 0

I am using a iOS library called Restkit, which automatically maps remote objects to local objects. You do that by creating a mapping using KVC pattern, and then loading with the mapping.

While I understand how it works, I don’t understand why some parts are implemented in certain ways. For example it uses a singleton pattern where you create an instance of RKObjectMapping like below:

RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping mapKeyPath:@"title" toAttribute:@"title"];
[articleMapping mapKeyPath:@"body" toAttribute:@"body"];
[articleMapping mapKeyPath:@"author" toAttribute:@"author"];
[articleMapping mapKeyPath:@"publication_date" toAttribute:@"publicationDate"];

However, when it comes time to actually use it, you access the manager by calling sharedManager of the class RKObjectManager, like following:

[[RKObjectManager sharedManager].mappingProvider setMapping:articleMapping
                                                 forKeyPath:@"articles"];

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/articles"
                                                  delegate:self];

What I don’t understand is, why even bother instantiating the class as articleMapping, when you will just access it using a class method/variable like sharedManager? Why not do something like:

[RKObjectMapping initWithClass:[Article class]];

I am a newbie so think there would be a good reason for taking this pattern that I am not aware of. Anyone know or understand why this would be implemented in this way?

  • 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-12T21:52:09+00:00Added an answer on June 12, 2026 at 9:52 pm

    When an object needs to access data associated to itself, it uses instance variables (ivars) to store that data. However, instance variables are part of a specific instance of the class and not the class itself – from a class method, they cannot be accessed. So, when the manager class you’re talking about was to store/access its private data, it uses a shared instance (singleton) to create instance variables. If it was used only as a class, it had to store its private data in global variables, which is considered bad practice in C.

    Also, if you look closely, the RKObjectManager class has properties. In Objective-C, properties are always backed by an underlying instance variable (be it created at runtime, dynamically, or at compile time, in a declared manner) – that’s why classes can’t have properties, and that’s why a singleton (an actual instance of a class) is needed.

    Example without singleton (ugly):

    static int uglyGlobalVar;
    
    @interface UglyClass: NSObject
    
    + (void)storeData:(int)data;
    
    @end
    
    @implementation UglyClass: NSObject
    
    + (void)storeData:(int)data
    {
        uglyGlobalVar = data;
    }
    
    @end
    

    Example with singleton (much better):

    @interface GoodClass: NSObject {
        int data;
    }
    
    + (GoodClass *)sharedInstance;
    
    @property (nonatomic, assign) int data;
    
    @end
    
    @implementation GoodClass: NSObject
    
    @syntehsize data;
    
    // also implement sharedInstance here
    
    @end
    
    // then this class is usable as:
    [GoodClass sharedInstance].data = 1337;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C library that I'm using from within an iOS Objective-C program.
I am using the StringEncryption.m library in iOS to encrypt messages, and then decode
I am creating an app using iOS 5 SDK. I managed to push views
I want to perform changes in the code which was developed using iOS 3.0,
I am creating a transparent image on iOS using Quartz. However, this image shows
Is it possible to create a playlist on iOS using the iPod Library Access
Am Captuing video using AVFoundation frame work .With the help of Apple Documentation http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html%23//apple_ref/doc/uid/TP40010188-CH5-SW2
I would like to develop an app using iOS gamekit library and I am
I'm using the official FBConnect library for iOS and trying to get it working
I'm building a static library, MyLibrary , for iOS in Objective-C that bundles together

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.