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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:24:25+00:00 2026-05-19T17:24:25+00:00

SO is telling me this question is subjective and likely to be closed. It

  • 0

SO is telling me this question is subjective and likely to be closed. It is indeed subjective, because I’m asking for the opinion of experienced Objective-C developers. Should I post this somewhere else? Please advise.


Fairly new to Objective-C, though fairly confident in the concept of writing OOP code, I’ve been struggling with the NSNotification vs Delegate dilemma from the start. I’ve posted a few questions about that subject alone. I do get the gist, I think. Notifications are broadcasted globally, so shouldn’t be used for notifying closely related objects. Delegates exist to hand over tasks to other object, that act on behalf of the delegated object. While this can be used for closely related objects, I find the workflow to be verbose (new class, new protocol, etc), and the word “delegation” alone makes me think of armies and bosses and in general makes me feel uneasy.

Where I come from (AS3) there are things called Events. They’re halfway between delegates and NSNotifications and pretty much ruled the world of flash notifying, until fairly recently, a Mr. Robert Penner came along and expressed his dissatisfaction with events. He therefore wrote a library that is now widely used in the AS3 community, called Signals. Inspired by C# events and Signals/Slots in Qt, these signals are actually properties of objects, that you access from the outside and add listeners to. There’s much more you can do with a signal, but at it’s core, that’s it.

Because the concept is so humble, I gave it a go and wrote my own signal class in Objective-C. I’ve gisted Signal.h/.m here.

A way to use this for notifying class A of an event in class B could look like this:

// In class b, assign a Signal instance to a retained property:
self.awesomeThingHappened = [[[Signal alloc] init] autorelease];

// In class a, owner of class b, listen to the signal:
[b.awesomeThingHappened add:self withSelector:@selector(reactToAwesomeThing)];

// And when something actually happens, you dispatch the signal in class b:
[self.awesomeThingHappened dispatch];

// You might even pass along a userInfo dictionary, your selector should match:
[self.awesomeThingHappened dispatchWithUserInfo:userInfo];

I hope it adheres to the right memory management rules, but when the signal deallocs, it should automatically remove all listeners and pass away silently. A signal like this isn’t supposed to be a generic replacement of notification and delegation, but there are lot’s of close counter situations where I feel a Signal is cleaner than the other two.

My question for stackoverflow is what do you think of a solution like this? Would you instantly erase this from your project if one of your interns puts it in? Would you fire your employee if he already finished his internship? Or is there maybe already something similar yet much grander out there that you’d use instead?

Thanks for your time, EP.


EDIT: Let me give a concrete example of how I used this in an iOS project.

Consider this scenario of four object types with nested ownership. There’s a view controller owning a window manager, owning several windows, each owning a view with controls, among which a close button. There’s probably a design flaw in here, but that’s not the point of the example 😛

Now when the close button is tapped, a gesture recognizer fires the first selector in the window object. This needs to notify the window manager that it’s closing. The window manager may then decide whether another window appears, or whether the windows stay hidden alltogether, at which point the view controller needs to get a bump to enable scrolling on the main view.

The notifications from window to window manager, and from window manager to view controller are the ones I’ve now implemented with Signals. This might have been a case of delegation, but for just a ‘close’ action, it seemed so verbose to create two delegate protocols. On the other hand, because the coupling of these objects is very well defined, it also didn’t seem like a case for NSNotifications. There’s also not really a value change that I could observe with KVO, because it’s just a button tap. Listening to some kind of ‘hidden’ state would only make me have to reset that flag when reopening a window, which makes it harder to understand and a little error prone.

  • 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-19T17:24:26+00:00Added an answer on May 19, 2026 at 5:24 pm

    Alright, after marinating the answers and comments for a bit, I think I have come to a conclusion that the Signal class I borrowed from AS3, has very little reason for existence in Objective-C/Cocoa. There are several patterns in Cocoa that cover the ranges of use that I was thinking of covering with the Signal class. This might seem very trivial to more experienced Cocoa developers, but it for me it was hard to get the spectrum complete.

    I’ve tried to put it down fairly concisely, but please correct me if I have them wrong.

    Target-Action

    Used only for notifying your application of user interaction (touches, mostly). From what I’ve seen and read, there’s no way to ‘borrow’ the target-action system for your own use

    KVO (key value observing)

    Very useful for receiving notifications when values change in accessible objects. Not so useful for notifying specific events that have no value attached to them, like timer events or interface followup events.

    NSNotification

    Very useful for receiving notifications when values change or other events happen in less-accessible objects. Due to the broadcast nature of the notification center, this is less suitable for cases where objects have a direct reference to another.

    Delegation

    Takes the most lines of code compared to the other three, but is also most suitable when the other three are not. Use this one when one object should be notified of specific events in the other. Delegates should not be abused for just accessing methods of the owner object. Stick to methods like ‘should’, ‘will’ and ‘did’.

    Signal

    It was a fun experiment, but I mostly used this for classic delegation situations. I also used it to circumvent linked delegates (c delegate of b, b delegate of a, where a starts the event that should make it to c) without wanting to resort to NSNotification.

    I still think there should be a more elegant solution for this edge case, but for now I’ll
    just stick to the existing frameworks. If anyone has a correction or another notification concept, please let me know. Thanks for your help!

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

Sidebar

Related Questions

StackOverflow is telling me this is a subjective question, but I think it's a
G'day, This is related to my question on star developers and to this question
When I read this question I remembered someone once telling me (many years ago)
This question might be a bit sketchy because I do not have the code
Ok I am using Sonar to check code quality. It's telling me this simple
I got a message on Facebook telling me to copy and paste this into
This question goes beoynd just programming, but I'd like to get some input on
Hi this question or problem i have its very hard i have search and
This question might be better asked over on ServerFault, but since this is related
This question is more on javascript principle. function done(){ console.log('done defined with `function done(){

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.