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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:27:44+00:00 2026-05-18T21:27:44+00:00

I am learning Objective-C and iOS programming through the terrific iTunesU course posted by

  • 0

I am learning Objective-C and iOS programming through the terrific iTunesU course posted by Stanford (http://www.stanford.edu/class/cs193p/cgi-bin/drupal/)

Assignment 2 is to create a calculator with variable buttons. The chain of commands (e.g. 3+x-y) is stored in a NSMutableArray as “anExpression”, and then we sub in random values for x and y based on an NSDictionary to get a solution. This part of the assignment is tripping me up:

The final two [methods] “convert” anExpression to/from a property list:

 + (id)propertyListForExpression:(id)anExpression;
+ (id)expressionForPropertyList:(id)propertyList;

You’ll remember from lecture that a property list is just any combination of NSArray, NSDictionary, NSString, NSNumber, etc., so why do we even need this method since anExpression is already a property list? (Since the expressions we build are NSMutableArrays that contain only NSString and NSNumber objects, they are, indeed, already property lists.) Well, because the caller of our API has no idea that anExpression is a property list. That’s an internal implementation detail we have chosen not to expose to callers.

Even so, you may think, the implementation of these two methods is easy because anExpression is already a property list so we can just return the argument right back, right? Well, yes and no. The memory management on this one is a bit tricky. We’ll leave it up to you to figure out. Give it your best shot.

Obviously, I am missing something with respect to memory management because I don’t see why I can’t just return the passed arguments right back.

Thanks in advance for any answers!

  • 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-05-18T21:27:45+00:00Added an answer on May 18, 2026 at 9:27 pm

    Consider what happens if you do this:

    NSArray *somePropertyList = [[NSArray alloc] initWithContentsOfFile:@"..."];
    id otherPropertyList = [SomeClass propertyListForExpression:somePropertyList];
    [somePropertyList release];
    
    // 'somePropertyList' has been destroyed...
    // is 'otherPropertyList' valid at this point?
    [otherPropertyList writeToFile:@"..." atomically:YES];
    

    The typical Objective-C pattern, therefore, is to retain and autorelease, so the caller still doesn’t have to manage the memory, but so the object doesn’t get destroyed too early:

    + (id)propertyListForExpression:(id)expr {
        // increments the retain count by 1
        // then sets it up to be decremented at some point in the future
        // (thus balancing it out, and the caller doesn't have to do anything)
        return [[expr retain] autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning objective-c, working through Aaron Hillegass' book Cocoa Programming for Mac OS X
So I am fairly new to objective C and iOS programming. I am learning
I'm currently learning myself objective-c and iOS programming and found myself stuck with non-working
I'm learning Objective C and iOS development. I'm trying to recreate some of the
I recently started learning Objective-C, and I am working on an iOS app as
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been
I am just starting climbing the Objective C learning curve (using Nerd Ranch iOS
I am learning Objective-C using Stephen Kochan's excellent book Programming in Objective-C 2.0. I
I want to start learning objective-c with book: Programming in Objective-C (4th Edition) .
I am learning iOS development in Objective-C, and I have found a lot of

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.