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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:44:30+00:00 2026-06-12T12:44:30+00:00

I have a cocos2d game setup which uses basic inheritance setup which is similar

  • 0

I have a cocos2d game setup which uses basic inheritance setup which is similar to this;

> Property (Base class)
> - Office : Property
> - Warehouse : Property
> - Bank : Property

All the properties live in an array listOfProperties and I am trying to print out each property in a NSLog, but I am not sure how to do it.

For example,

// Create an office
Office *o = [Office alloc] init];
[o setName:@"Some office"];
[city.listOfProperties addObject:o];
[o release];

// Debug output all the properties in the game
// city.listOfProperties in an array of Property objects
for (Property *prop in city.listOfProperties) {

    // I want to print out all the different properties here
     if ([prop isKindOfClass:[Office class]]==YES)
     {
         NSLog(@"Office");
         NSLog(@"office.name = %@", prop.name); // Prop name does not work 
     }
} // next

The problem is that some properties do not share the same attributes. For example, an Office might have “floors” but a Warehouse has “capacity”.

What I’m needing is to print out all the different properties, but I am not sure how to change the focus from the pointer prop to a pointer for the specific class (ie: Office).

I need them all to live in listOfProperties so that I can use it later on in a CCMenu and want to avoid splitting them up into seperate arrays which will be very hard for me to manage.

Is there a way to do this?

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-06-12T12:44:31+00:00Added an answer on June 12, 2026 at 12:44 pm

    Do typecasting like this.

    for (Property *prop in city.listOfProperties) {
    
     if ([prop isKindOfClass:[Office class]])
     {
         Office* officeObject = (Office*) prop;
    
         NSLog(@"office.name = %@", officeObject.name);
     }
     if ([prop isKindOfClass:[Warehouse class]])
     {
         Warehouse* WarehouseObject = (Warehouse*) prop;
    
         NSLog(@"Warehouse.name = %@", WarehouseObject.name);
     }
     if ([prop isKindOfClass:[Bank class]])
     {
         Bank* BankObject = (Bank*) prop;
    
         NSLog(@"Bank.name = %@", BankObject.name);
     }
    

    }

    You can have whatever variables you want to log. using name for example.

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

Sidebar

Related Questions

I have a cocos2d powered game that uses UIKit menues, so I only use
In my cocos2d game i have a some balls which must be destroyed, and
I have a usual iOS Cocos2d game. I start with a MainMenuViewController, which then
I have game application (cocos2d) in which, a ball is to be shooted from
I have a Cocos2D game I want to install on my devices with Testflight.
I have writing a small shooting game in cocos2d. Winning the game is to
I'm currently developing a doodle-jump style game in Cocos2d for iPhone and have a
I have successfully implemented slider to my Cocos2D project using this resource . The
I have a Cocos2d/openGL iPhone game. It's a universal app and I'm dealing with
I have a game made in cocos2d for iPhone, I've adapted for iPad and

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.