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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:17:41+00:00 2026-06-09T15:17:41+00:00

Does anyone know how to add a property in objective c – but that

  • 0

Does anyone know how to add a property in objective c – but that property is also a custom made class?

For instance, I made this class:

@interface Person : NSObject

@property NSString *personName;
@property NSNumber *personAge;

-(id)init;

@end

Where…

@implementation Person

@synthesize personAge, personName;

-(id)init{
    self = [super init];

    if(self){
        self.personAge = [NSNumber numberWithInt:26];
        self.personName = @"Jamie";
    }
    return self;
}

@end

So basically whenever I init & alloc the Person class, it gets setup with personAge as 26 and personName as Jamie.

Now I want to create a bank account class which contains a person property:

@interface BankAccount : NSObject

@property NSNumber *bankAccNumber;
@property (nonatomic) Person *thePerson;

-(id)init;

@end

Where…

@implementation BankAccount

@synthesize thePerson = _thePerson;
@synthesize bankAccNumber;

    -(id)init{

        self = [super init];

        if(self){
            bankAccNumber = [NSNumber numberWithInt:999];
        }

        return self;
    }
    @end

Now – my issue is this:

1) In the BankAccount class, where do I alloc & init the Person class?

  • 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-09T15:17:42+00:00Added an answer on June 9, 2026 at 3:17 pm

    To stay with your example

    @implementation BankAccount
    
    @synthesize thePerson = _thePerson;
    @synthesize bankAccNumber;
    
    -(id)init{
    
        self = [super init];
    
        if(self){
            bankAccNumber = [NSNumber numberWithInt:999];
            thePerson = [[Person alloc] init];  // <- **** HERE
        }
    
        return self;
    }
    @end
    

    Of course, in general, you do not want everybody to be 26yo Jamies and have 999$, but I guess you plan to improve on these details later 🙂

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

Sidebar

Related Questions

Does anyone know how to add an item to a list but do it
Does anyone know the display formatter that I would need to add to the
Does anyone know how to modify the Wordpress canonical links to add a custom
Does anyone know of a way to add additional attribute types to the @property
Does anyone know if there is a way to add a property to a
Does anyone know how to add a border to a Dockpanel. i have this:
Does anyone know how to add full (n.n.n.n) Windows file version information to COM
Does anyone know how to add a listener to the action overflow menu button
Does anyone know how to add a subversion branch to hudson and have it
Does anyone know of a quick way to add a role CRUD system to

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.