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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:40:31+00:00 2026-05-20T12:40:31+00:00

hoping for advice on something. I have a Levels Engine class that creates an

  • 0

hoping for advice on something.

I have a Levels Engine class that creates an NSMutable Array called levelsArray.

I am passing the data to a Levels View Controller which is working just fine.

I also have a Particle Emitter class to which I am hoping to pass the level data.

However I am constantly being told that the count level of the array is 0 when I pass it to the Particle Emitter class.

The array has been setup properly:

    **LevelsEngine.h**  
    @interface
    LevelsEngine : NSObject {   
    NSMutableArray *levelsArray;         }

    @property (retain) NSMutableArray
    *levelsArray;  




    **LevelsEngine.m**  
    @synthesize levelsArray;  
    LevelsArray =[NSMutableArray array];


    **Code used in ParticleEmitter.m**   
    newlevelsArray = [NSMutableArray array];  
    newlevelsArray=view.levelsArray;

Am I right in thinking I am having this error because I am trying to pass the array data from one NSObject to another and not to a view controller?If so how can I pass the data?

  • 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-20T12:40:32+00:00Added an answer on May 20, 2026 at 12:40 pm

    Couple of things.

        **Code used in ParticleEmitter.m**   
        newlevelsArray = [NSMutableArray array];  
        newlevelsArray=view.levelsArray;
    

    The first line is creating a new array.
    The 2nd line is assigning newlevelsArray to be a pointer to the array in view.levelsArray, leaving the object you created in line #1 orphaned.

    I think you were intending the 2nd line to be a field by field copy of the array, but assignments of objects don’t work that way.

    You can fix this by 2 things.

    1) Remove the first line newlevelsArray = [NSMutableArray array];

    2) Change the 2nd line to `newlevelsArray = [view.levelsArray copy];

    This will actually do a copy, which is probably what you want since you can then go ahead and modify newlevelsArray in ParticleEmitter.m without changing the value in view.

    Important note: don’t forget to create a -dealloc: method in your Particle emitter class which releases newlevelsArray:

    -(void)dealloc {
       if (newlevelsArray) [newlevelsArray release];
       [super dealloc];
    }
    

    An alternative solution is to use setters.

    Instead of:

    2) Change the 2nd line to newlevelsArray = [view.levelsArray copy];

    Do:

    2) Change the 2nd line to this.newlevelsArray = view.levelsArray;
    Where you have to define newlevelsArray to be a property of the ParticleEmitter class using

    @property (copy) NSMutableArray * newlevelsArray;

    Note the use of “copy” instead of “retain”. This will do a field by field copy of the array, which is most likely advisable for containers of mutable objects.

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

Sidebar

Related Questions

I was hoping to get some advice on what to do. I have a
I have some javascript which runs a timer that animates something on the website.
I have posted this question on the Ext-GWT forums, I am just hoping that
Hoping I can get some architectural advice on this. I have been given the
Hoping that someone here will be able to provide some mysql advice... I am
I am a three week old Rails newbie and I have something that I
I was hoping for some advice on how to restrict user access to subdomains.
Hoping that someone can help clear up this very annoying situation I find myself
Hoping Paul McGuire may spot this and rescue me... I have grabbed the 'regex
In mysql, I have a tree that is represented using the adjacency list model.

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.