You have a scope problem with your code. The contactsObjects
variables in viewWillAppear:
are not related to the ivar you have called contactsObjects
. You're declaring new variables that are using the same name. The NSLog()
at the end, on the other hand, is the ivar. But setting those other variables didn't put anything into the ivar, so you see (null)
, which is how NSLog()
represents "no object".
Fix this by not making new variable declarations, but using the ivar.
if (granted) {
contactsObjects = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
contactsObjects = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
You will also need to cast these:
contactsObjects = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
(Also, the function doesn't return a mutable array, so you may have trouble down the road with that.)
The second problem is that ABAddressBookRequestAccessWithCompletion()
doesn't stop and wait for its completion Block to run. While access is being requested, the rest of your method carries on, so you reach the NSLog()
before contactsObjects
is actually set in that case.