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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:22:59+00:00 2026-05-24T05:22:59+00:00

I have an NSNotification observer in class A named Test. The observer calls a

  • 0

I have an NSNotification observer in class A named Test. The observer calls a method, checker:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checker:) name:@"Test" object:nil];

Then I have two posts in classes B and C, both to the observer named Test

[[NSNotificationCenter defaultCenter] postNotificationName:@"Test" object:self];

I’d like to be able to know which post is being sent to the observer and increment a counter to be usable in the check method, something like:

-(void)check {
    if ([classB count] <= [classC count]) {
        NSLog(@"boom");
    }
}

I’ve seen suggestions to use the userinfo to do so but im not quite sure how; is the counter object instantiated in class B/C and passed as an int or dictionary etc

Any help greatly appreciated
Thanks

  • 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-24T05:23:00+00:00Added an answer on May 24, 2026 at 5:23 am

    Well you need to have your counter in class A. Than you can do this in checker: function

    - (void)checker:(NSNotification *)notification
    {
        if ([notification.object isKindOfClass:[BClass class]]) {
            bCounter++;
        }
        else if ([notification.object isKindOfClass:[CClass class]]) {
            cCounter++;
        }
    
        if (bCounter < cCounter) {
            NSLog(@"boom");
        }
    }
    

    Let me know if it works for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've added an observer for my method: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeViewAfterUpdating) name:@labelUpdatedShouldReturn object:nil]; Then
I have a class with 2 NSNotifications implemented //Set up notifications [[NSNotificationCenter defaultCenter] addObserver:self
I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a
I have class ParentClass that observes an NSNotification. ParentClass handles the notification. ChildClass inherits
I'm study about NSNotificationCenter. Here is my code Observer.m //note init method is not
I have an observer which looks like this: class CommentObserver < ActiveRecord::Observer include ActionView::Helpers::UrlHelper
I have an Objective-C++ class that adds itself as an observer for an event
i have a viewcontroller .In it there is a nsnotification observer in it. i
I have an observer of NSNotification which is called twice. I do not know
I have a data object -- a custom class called Notification -- that exposes

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.