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

  • Home
  • SEARCH
  • 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 6241613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:47:57+00:00 2026-05-24T11:47:57+00:00

I have a NSMutableArray property in my AppDelegate called blocks. I would like to

  • 0

I have a NSMutableArray property in my AppDelegate called blocks.
I would like to observe whenever an object is added to this array.
I’ve read other posts, but I can’t understand why this isn’t working.

In my app delegate class, I implement

- (void)insertObject:(id)obj inBlocksAtIndex:(NSInteger)index
{
    [blocks insertObject:obj atIndex:index];
}

In my view controller’s init method, I add an observer to my AppDelegate reference.

boardModel = [[UIApplication sharedApplication] delegate];
[boardModel addObserver:self forKeyPath:@"blocks" options:0 context:NULL];

In my view controller’s viewDidLoad method, I try invoking the KVO Indexed array accessor I implemented previously,

[boardModel insertObject:[[Block alloc] init] inBlocksAtIndex:0];

Then I implement my observeValueForKeyPath method:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"blocks"])
    {
        NSLog(@"ADDED");
    }
}

I’ve tried adding an NSLog statement before the if statement in observeValueForKeyPath, and it seems as if it’s never being called.

I’ve also tried NSLogging [[boardModel blocks] count], and it says the count is 1 (the object is being added).

I must be missing something.

  • 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-24T11:47:58+00:00Added an answer on May 24, 2026 at 11:47 am

    You’re observing the blocks property of the app delegate, not the blocks array itself. Hopefully the following example will make the difference clear:

    // This will fire KVO as you're changing the app delegate's `blocks` property.
    appDelegate.blocks = [NSMutableArray array];
    
    // This will not fire KVO as the app delegate's `blocks` property still points
    // to the same object; from the app delegate's perspective, nothing's happened.
    [appDelegate.blocks addObject:@"Object"];
    

    If you want to be notified when the contents of the blocks array changes, observe a property on the array itself—something like count. Updating your code:

    [boardModel.blocks addObserver:self forKeyPath:@"count" options:0 context:NULL];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to observe the count property of an NSMutableArray object. I was
I have an NSMutableArray of objects. Each object has a property called Name. I
I have a class wich is initialized like this. // myclass.h @property(nonatomic,retain) NSMutableArray *daysOfWeek;
Suppose I have something like this: @property (readonly) NSMutableArray *someArray; Can I modify [obj
Do I have this right ... // Reactor.h @property(nonatomic, retain) NSMutableArray *reactorCore; // Reactor.m
I've been running into this problem a lot lately. I have an NSMutableArray called
In my Brain model I have an NSMutableArray property called stockCars which holds 8
I have an Obj-C 2.0 class that has an NSMutableArray property. If I use
I have an NSMutableArray. It's members eventually become members of an array instance in
What i'm trying to accomplish is to have an NSMutableArray defined in the AppDelegate.

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.