0

We have address book feature in our application, contacts are stored in NSMutableArray. I

have a separate class which is accessing contacts from outside, so I have initialized like

below in new class...

self.newListdata = [address_book_window listData];

Now my new class is able to access all contact using newListdata, number of contacts also

matching. In one situation if any contacts deleted from address book at run time, new

class newListdata also need to be updated, but it is not updating as I thought. Count is

also not updating. Am I doing anything wrong, Do I need to manually delete the contact in

newListdata also. Why it is not synchronized with address book contact as I am pointing to

address book list data.I have been learning objective C, so if anyone can help it will be

useful. thanks.

6
  • how is your "newListdata" property declared? Commented Mar 21, 2013 at 11:41
  • do you whant synchronize the class like a singletone? Commented Mar 21, 2013 at 11:41
  • @MichaelDautermann property (strong, nonatomic) NSMutableArray * newListdata; Commented Mar 21, 2013 at 11:44
  • 1
    @Kunal reloading will work, if my array get updated right? my array is having old count its not updating. Commented Mar 21, 2013 at 11:53
  • 1
    address_book_window is handling all the data correct? Does it automatically notifies the viewcontrollers that are using its services? Commented Mar 21, 2013 at 11:57

2 Answers 2

1

compare if newListdata and [address_book_window listData] are the same pointer (the same object).

printf("compare %f and %f", newlistdata, [address_book_window listData])

They should be the same address storage.

Note: since i don't know how you have implemented your code, since listData is encapsulated, address_book_window doesn't guaranty listData will always be at the same address storage (if you use a new list data by example). So newListData will could potentially point to a dangling pointer.

Best way to keep track of an object like this is by observer pattern, or KVO if you can. Since they are long to explain, google it ;)

Sign up to request clarification or add additional context in comments.

Comments

1

if you have 2 NSMutableArrays they have strong references to the same objects, but they are 2 unique objects (they are 2 MutableArrays), this is the case when for example you create a NSMutableArray arrayWithArray:

if you have 1 Array, and 2 references to it when you remove or add object to it, it's a single object so it does not matter which reference you use to access it, it will be in "sync" as you mention (saying in sync is not correct because in fact they are 1 single object)

In your case maybe listData return a new array that contains references to the same objects, in such a case when you remove an object from one array, the second will still retain it (the object will not be deallocated then) and the 2 arrays will be different.

1 Comment

Getter method will be called when I call, As you mentioned above, will it return new array? If so how can I modify my code to return only reference to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.