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 7555301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:34:23+00:00 2026-05-30T11:34:23+00:00

lets say i have classA which is a class of audio,that sample the audio

  • 0

lets say i have classA which is a class of audio,that sample the audio input many times.
each time class A get a new data (can happen many times in second), he needs to inform another class, which is classB.

Now, i could just make an instance of class B in classA and call B when there is a new data arrived, but this is not a modular software.

i want classA to be “blind” to the outside, and just to add him to every project, and to have another classB that will register him some how, so when A has something new, B will know about it,(without A calling B ! )

how its done right in objective c ?

thanks a lot .

  • 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-30T11:34:25+00:00Added an answer on May 30, 2026 at 11:34 am

    You can post a notification in ClassA, and register for that notification in other classes (namely ClassB).

    This is how you can do it:

    (in ClassA):

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

    (in ClassB):

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

    Whenever an instance of ClassA posts a new notification, other instances that have registered to that notification will be informed (instantaneously). In this case, ClassB will perform doSomething:(NSNotification *)note.


    [Edit]

    You can post that notification your setter method (setVar:(NSString*)newVar).

    If you want to pass something along, use the postNotificationName:object:userInfo: variant. userInfo is a NSDictionary and you can pass anything you want in it. for example:

    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:var, @"variable", nil];
    [[NSNotificationCenter defaultCenter]
    postNotificationName:@"noteName" object:self userInfo:dic];
    

    now, edit your doSomething: method:

    -(void)doSomething:(NSNotification*)note {
        if ([[note name] isEqualToString:@"noteName"]) {
            NSLog(@"%@", [note userInfo]);
        }
    }
    

    More info:
    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html

    https://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Notification.html

    https://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/MacOSXNotifcationOv/Introduction/Introduction.html

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

Sidebar

Related Questions

Alright lets say I have a cPlayer class that inherits from cOrganism , which
Lets say I have classA which contains classB and both are [Serializable]. I assumed,
Let's say I have a class that has a member called data which is
Lets say I have a controller class A which implements UIImagePickerControllerDelegate. within A ,
Lets say I have object Tom which has class Person. Class Person String Name
lets say I have an NSWindow Class, that has several events for mouse and
Lets say you have a class SomeClass which has its own implementation of toString()
So lets say that in my entry point class (i.e the class which runs
Lets say I have a class called PageBuilder which I instantiate, send parameters to
Lets say I have Class A, that calls static methods in either Class B

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.