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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:37:27+00:00 2026-05-21T12:37:27+00:00

Hi im trying to retrieve an object of a specific class from an NSMutableArray,

  • 0

Hi im trying to retrieve an object of a specific class from an NSMutableArray, and then add it to self: eg:

- (void) init{
     _Objects = [[NSMutableArray alloc]init];
     Psychicing *psy = [[Psychicing alloc]init];
     [psy startPsychic];
     [_Objects addObject: psy];
     [psy release];
}

This creates an object of class Psychicing, then runs the [psy startPsychic] method to create the internals of the class object. Then I add the psy object to _Objects NSMutableArray.

-(void)startPsychic{
      id psychicParticle = [CCParticleSystemQuad ......]; //is Synthesised with (assign)
      //Other things are set here such as position, gravity, speed etc...
}

When a touch is detected on screen, I want to take the psy object from the _Objects array and add it to self: Something like this (Although this gives runtime error)

-(void) Touches.....{

     for (Psychicing *psy in _Objects){
          [self addChild: psy.psychicParticle];
     }
}

I hope i have explained it clearly enough, if you need more clarification let me know.
So basically:
[MainClass Init] -> [Psychicing startPsychic] -> [MainClass add to array] -> [MainClass add to self]

  • 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-21T12:37:28+00:00Added an answer on May 21, 2026 at 12:37 pm

    I’m assuming the _Objects (which should be a lowercase o to follow conventions) is storing objects other than the Psychicing object and you’re trying to pull just the Psychicing object out of it in the -(void)Touches… method (which also should be lowercase). If so, you could do:

    for (id obj in _Objects)
    {
      if ([obj isMemberOfClass:[Psychicing class]])
        [self addChild:obj.psychicParticle];
    }
    

    That will cause only the Psychicing objects in the array to be added as a child to self.

    It looks like you do have another error though if the code you pasted in is your real code. Init should be defined as:

    - (void) init{
         _Objects = [[NSMutableArray alloc]init];
         Psychicing *psy = [[Psychicing alloc]init];
         [psy startPsychic];
         [_Objects addObject: psy];
         [psy release];
    }
    

    with _Objects defined as an instance variable (or property) in the class’s interface. As you wrote it, it’s a method variable in the init method and is leaking. So when you try to access _Objects in -touches, _Objects is most likely nil.

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

Sidebar

Related Questions

I am trying to retrieve results from a SQlite table, and then assign them
I'm trying to retrieve a file from a server using SFTP (as opposed to
I'm trying to retrieve an XML stream from a URL. For most URLs my
I'm trying to retrieve data from an SQL Server 2000 server, and place into
I am trying to use ResourceBundle#getStringArray to retrieve a String[] from a properties file.
I having a hierarchy collection object where I am trying to retrieve the last
In Java, I'm trying to retrieve a HashMap<String, Object> that has the Object which
I'm trying to retrieve the text value from a JTextField but first I need
I am trying to retrieve two listviews from an ascx control for the purpose
I am trying to retrieve a user on Sharepoint's user photo through the WSS

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.