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

The Archive Base Latest Questions

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

I not at all a pro at developing in C languages. Just experimenting with

  • 0

I not at all a pro at developing in C languages. Just experimenting with these things for fun. My problem is probably just a pointer/alloc issue, but I just cannot figure it out.

My problem is that when I create two instances of a class called Port and want to assign different values to a variable inside that instance. The value of product1 and product2, but when I change one of them, the other instances gets the same value. What I want of course is being able to define different values to the variables of each instance.

The variable are declared in the Port class like this:

NSObject *product1, *product2; 

And the method to change them is this one:

-(void) setProducts: (NSObject*)setProduct1 andTwo: (NSObject*)setProduct2
{
    product1 = setProduct1;
    product2 = setProduct2;
}

Inside the main I create the ports in the init function

   Port *port1 = [[Port alloc] init];        
    [port1 setProducts:@"uno" andTwo: @"dos"];       
    [ports addChild:[port1 getMenuItem]];    

    Port *port2 = [[Port alloc] init];
    [port2 setProducts: @"tres" andTwo: @"viero"];
    [ports addChild:[port2 getMenuItem]];

I hope I have informed you enough and that you can help out. If I need to add more information feel free to ask.

  • 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-27T03:18:13+00:00Added an answer on May 27, 2026 at 3:18 am

    It looks like you’re saying those variables are declared something like this:

    // Port.m
    
    #import "Port.h"
    
    NSObject *product1, *product2;
    
    @implementation Port
    
    // Method implementations...
    
    @end
    

    Which means that those are the Objective-C version of “class variables”. Every instance of the class has access to them, but they’re the same variable for every instance. If you want instance variables, you should put them in the class’s interface declaration, like so:

    @interface Port : NSObject 
    {
        NSObject * product1;
        NSObject * product2;
    }
    
    // Declare methods...
    
    @end
    

    See also: Learning Objective-C: A Primer

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

Sidebar

Related Questions

OK, I've just got myself a shiny new MacBook Pro, and having been developing
First of all, I'm not a pro on IIS configuration topic. I got a
First of all, im new here, and im (not) a pro ;) (but i
Although obviously not all scenarios can be covered by a single design, is it
I'm not all that familiar with jquery so I'm not quite sure how to
I am reading log files but not all lines want to be processed straight
I have a grouped UITableView where not all sections may be displayed at once,
Lately I had to change some code on older systems where not all of
Many, if not all, of my old VC++ 6.0 MFC apps don't work in
Situation: Site with content protected by username/password (not all controlled since they can be

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.