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

  • Home
  • SEARCH
  • 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 590659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:33:11+00:00 2026-05-13T15:33:11+00:00

I have a question about how instance variables work and when to use the

  • 0

I have a question about how instance variables work and when to use the @property. Here is an example interface file I am working with

@interface PackageModel : NSObject {
    NSString *tracking;
    NSString *carrier;
    NSString *status;
    NSMutableDictionary *events;

    // Connection ivars
    NSMutableData *receivedData;

    // Parsing ivars
    int tagLevel;
    NSMutableArray *tagTree;
    NSString *parentTag;
    NSString *currentTag;
}

@property (nonatomic, retain) NSMutableData *receivedData;

- (id)initWithTrackingString:(NSString *)string;
- (void)getPackageDataWithEvents;
- (void)printMe;

@end

How can I access these in the file’s code. Can I access tracking, carrier, and status in this class’s methods just by using something like

tracking = [[NSString alloc] initWithString:@"Hello World"];

Also, what variables need to be put in the dealloc? Only the variables I have in the @property/@synthesize? Or do I need to release all the instance variables in the dealloc method.

I am just looking for some clarification on how instance variables work in Objective-C. Thanks.

  • 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-13T15:33:11+00:00Added an answer on May 13, 2026 at 3:33 pm

    @property declarations are nothing more than compiler-generated getter and setter methods. That’s it. Just the methods. Obviously, you have to be getting and setting something, so we create the ivar that goes along with the getters and setters. In your example above, your compiler is generating:

    - (NSMutableData *) receivedData;
    - (void) setReceivedData:(NSMutableData *)newReceivedData;
    

    The getter returns the value in the receivedData instance variable, and the setter changes the value in the receivedData instance variable.

    (Side note: with the 64-bit runtime, you can skip declaring the instance variable, but I still like to put it in just to be explicit)

    As for what you should do in your dealloc method, you need to release the instance variables that have been retained or copyed. So in your example, you’ll need to do [receivedData release]; in your dealloc method, because when you set the receivedData ivar, you retained the new value (that’s what the retain means on the @property line). If you don’t specify either retain or copy in the @property declaration, then it defaults to assign, and you don’t have to do anything. Beyond this, you’ll need to release any other instance variables that you retained yourself (ie, not through an @property (retain) setter).

    For your last question, yes you can just do:

    tracking = [[NSString alloc] initWithFormat:@"Hello, %@!", @"world"];
    

    Inside your own class, you have direct access to all your own instance variables (and any protected and public ivars of your super classes).

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

Sidebar

Ask A Question

Stats

  • Questions 309k
  • Answers 309k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Curl seems to send all output to standard error, not… May 13, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer I found the problem, which is quite trick. The msmq… May 13, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer Similar to the previous answers, but this illustrates how to… May 13, 2026 at 9:52 pm

Related Questions

My question is how does one abstract a database connection from the model layer
I have a product image class. This is an object with re-use potential for
In the type of embedded programming I'm getting into, determinism and transparency of the
I've never used Smalltalk, but I've read a lot about it and it has
I've been working for years with VS's debugger, but every now and then I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.