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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:04:13+00:00 2026-05-12T19:04:13+00:00

I am a little confused about how I set and get the instance variables

  • 0

I am a little confused about how I “set” and “get” the instance variables for an object that is contained within another. As you can see from the code below I first create a RocketBody which includes a SolidRocketMotor object. I am creating the SolidRocketMotor in RocketBody init and deallocating it in RocketBody dealloc.

My question is how would I go about setting / getting the engine (SolidRocketMotor) instance variables from within main (e.g. setting engCase)?

int main (int argc, const char * argv[]) {
    RocketBody *ares_1x;

    ares_1x = [[RocketBody alloc] init];
    [ares_1x setFuel: [NSNumber numberWithInt:50000]];
    [ares_1x setWeight:[NSNumber numberWithFloat:1.8]];
    // How to set engCase to "Standard" here?
...

.

@interface SolidRocketMotor : NSObject
{
    NSString *engCase;        
    NSString *engPropellant;  
    NSNumber *engIgniter;    
    NSString *engNozzle;      
}
@property(copy) NSString *engCase;
@property(copy) NSString *engPropellant;
@property(copy) NSNumber *engIgniter;
@property(copy) NSString *engNozzle;
@end

@interface RocketBody : NSObject
{
    NSNumber *fuel;
    NSNumber *weight;
    BOOL holdDownBolt_01;
    BOOL holdDownBolt_02;
    BOOL holdDownBolt_03;
    BOOL holdDownBolt_04;
    SolidRocketMotor *engine;
}
@property(copy) NSNumber *fuel;
@property(copy) NSNumber *weight;
@property BOOL holdDownBolt_01;
@property BOOL holdDownBolt_02;
@property BOOL holdDownBolt_03;
@property BOOL holdDownBolt_04;
@end

// ------------------------------------------------------------------- **
// IMPLEMENTATION
// ------------------------------------------------------------------- **

@implementation SolidRocketMotor
- (id) init {
    self = [super init];
    if (self) NSLog(@"_init: %@", NSStringFromClass([self class]));
    return self;
}

@synthesize engCase;
@synthesize engPropellant;
@synthesize engIgniter;
@synthesize engNozzle;

- (void) dealloc {
    NSLog(@"_deal: %@", NSStringFromClass([self class]));
    [super dealloc];
}
@end

// ------------------------------------------------------------------- **

@implementation RocketBody
- (id) init {
    self = [super init];
    if (self) {
        engine = [[SolidRocketMotor alloc] init];
        NSLog(@"_init: %@", NSStringFromClass([self class]));
    }
    return self;
}

@synthesize fuel;
@synthesize weight;
@synthesize holdDownBolt_01;
@synthesize holdDownBolt_02;
@synthesize holdDownBolt_03;
@synthesize holdDownBolt_04;

- (void) dealloc {
    NSLog(@"_deal: %@", NSStringFromClass([self class]));
    [engine release], engine = nil;
    [super dealloc];
}
@end

many thanks

gary

  • 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-12T19:04:13+00:00Added an answer on May 12, 2026 at 7:04 pm

    You need to provide an accessor for engine in your RocketBody class. Like this:

    @interface RocketBody : NSObject
    {
        // ...
        SolidRocketMotor *engine;
    }
    // ...
    @property(retain) SolidRocketMotor *engine;
    @end
    
    @implementation RocketBody
    // ...
    @synthesize engine;
    // ...
    @end
    

    With this, external code can access the engine property:

    // Obj-C 2.0 Property style:
    ares_1x.engine.engCase = @"Standard";
    
    // or setter/getter method style:
    [[ares_1x engine] setEngCase:@"Standard"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m a little confused about this point. Everything that I found in books, blogs,
I am a little confused about the HttpApplication events. I have a SessionService* that
I am little confused about how to create Master Detail view with two different
I'm a little confused about what setting a thread to be a daemon means.
I'm a little confused about the StripTags filter as used in Zend. I think
I was browsing Facebook's documentation reading about canvas applications and I came across an
So I'm making a Load.c file, that basically will load a bunch of students
Trying to figure out the best way to accomplish this. I have inhereted a
As a small exercise I am trying to write a very small, simple game
As far as my understanding goes, once we complete the 'listen' call with bound

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.