Objective C - NSMutable Array Not Assigning Data Correctly

First question, i am confused by your use of self. Assuming these are variables in a class, you only need to use self to call class methods. Assuming products is declared in the interface as

Code:
NSMutableArray *products;

then the following code is sufficient

Code:
products = [[NSMutableArray alloc].....];

[products addObject:Object];

if the class had a method loadObjects

Code:
[self loadObjects]

If products is a synthesised property, you could use the setter method:
Code:
NSMutableArray *product_array = [[NSMutableArray alloc].....];
[self setProducts:product_array];

Also, if products is a synthesised property, when you call

Code:
[self products]

You are literall calling a getter method, called products, that returns the variable of products. The getter method is read only, and seperate from the setter method which by default takes the form setVariable.
 
Last edited:
tbh I only added self.XXX because I was just making sure that everything was linking correctly whilst trying to figure out this bug. It's not needed, but it's not the problem and does the same as not including .self, the problem appears regardless of using 'self.' or not.

Just for clarification, "products" is an NSMutableArray defined in the header (.h) file and made public by the @property in the header (.h) and @synthesize in the implementation file (.m).

The screen shots above are from a function that processes incoming data from a HTTP request, it creates a new product (named Prod in the screen shots) and then assigns it to an NSMutableArray to be used at a later time.

Just befor someone suggests it, I have tried just plain initialization and then adding the object afterwards like so:
Code:
products = [[NSMutableArray alloc] init];
            [products addObject:Prod];
But that has no effect either. On the other hand if I declare a brand new object and try to assign "Prod" to that then it works fine.
Code:
NSMutableArray *Products = [[NSMutableArray alloc] init];
            [Products addObject:Prod];
 
Last edited:
Ok, ignore this entire thread, I was right, I'm just being stupid because I'm tired. The pointers don't actually show in the NSMutableArray debug information, they are all referenced as 0x0 but they are in fact there as I can pull information from them no problem, it's just that I was pulling information out and putting it into another array so all I saw was errors without testing the real output.

I don't know if this is a bug in xCode that it's not displaying correctly or something I've done that's sending it a bit loopy, but it's rather annoying that it doesn't show the pointers correctly.
 
Back
Top Bottom