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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:25:29+00:00 2026-06-08T21:25:29+00:00

I’m new to Objective-C and XCode, but I was happy to see that XCode

  • 0

I’m new to Objective-C and XCode, but I was happy to see that XCode 4.4 automatically synthesizes my properties for me, now. I figure this means that I no longer have to type out @synthesize for my properties, and that I get to access them using self.propertyName = @"hi";, for example.

I’m trying to re-write some example code so that I can understand it better, but this code implements a custom getter method. In the example code, the property is manually synthesized, as @synthesize managedObjectContext = __managedObjectContext;. The custom getter looks like this:

- (NSManagedObjectContext *)managedObjectContext {
    if (__managedObjectContext != nil) {
        return __managedObjectContext;
    }
    
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        __managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
        [__managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    
    return __managedObjectContext;
}

In this person’s code, I see he’s just using his manually synthesized accessor to both get and set. I figured in my code, I could just replace the __managedObjectContext with self.managedObjectContext, but nope. If I do this, I get an error telling me that I am trying to assign to a readonly property. This makes sense, because that property is defined as readonly, by this other coder.

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;

So, I figure something about how he’s manually synthesizing his property means that if he uses that specified setter, it allows him to set a readonly property somehow.

If I manually synthesize the property, like in the code I am referencing, everything goes back to working, but that’s not making use of the new automatic synthesize. If I remove the readonly, I can set this property, as expected, but I feel like I’m not understanding why he has it as readonly, so I bet I’m breaking something there.

So, am I misusing the new automatic synthesize? How do I set this using the setter, if the automatic synthesize is not creating it for me, because of readonly?

  • 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-08T21:25:30+00:00Added an answer on June 8, 2026 at 9:25 pm

    When XCode auto-synthesizes, it simulates the following…

    @synthesize foo = _foo;
    

    So, you can access the data appropriately with self.foo or object.foo.

    However, in the implementation of accessor methods (and initializers and dealloc), you should use the iVar directly.

    Note, those iVars have two underscores. And, they are being manipulated in the accessor method. Use _managedObjectContext, and you should be good to go.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.