Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer confusion

I am confused about one pointer situation explained below;

In class A

@property(nonatomic,retain)NSMutableArray *words;

In class B

 @property(nonatomic,retain)NSMutableArray *words;

 //creating a pointer to words from classB
 self.words = [classB words];

Now if I add new word to words array in Class A, why don't I see that word in words array in class B? I thought my words array in Class B is a pointer to Class A words?

like image 363
Cyprian Avatar asked Dec 08 '25 03:12

Cyprian


1 Answers

Basically the changes should reflect in both arrays, until you change the reference of any of the two objects some where in your code.

//creating a pointer to words from classB
self.words = [classB words];

And some where in your Class A or Class B,

self.words = someOtherArray;

This will make the words array of both the classes to point different objects.

like image 130
EmptyStack Avatar answered Dec 10 '25 17:12

EmptyStack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!