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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:11+00:00 2026-06-14T13:51:11+00:00

I come from a .NET web application background and have just started iOS development.

  • 0

I come from a .NET web application background and have just started iOS development. The initial design of my app focuses around the NSNotificationCenter. I was reasonably happy with this until I saw various posts explaining how reaching for the NSNotificationCentre was a common newbie mistake.

Here is a simplified version of the problem I am trying to address:

My application is trying to show a list of messages that are populated using web service calls, think Facebook messaging.

When the app is first loaded it pulls a collection of messages from the server and displays them in a table to the user. The user can add new messages (which get sent back over the API) and the app can receive Push Notifications about new messages which are added to the feed.

The messages are never persisted to disk so I’m just using POCOs for the model to keep things simple.

I have a MessageFeedController which is responsible for populating the message feed view (in a storyboard). I also have a message feed model, which stores the currently retrieved values and has various methods:

  • (void) loadFromServer;
  • (void) createMessage: (DCMMessage*) message;
  • (void) addMessage: (DCMMessage*) message;
  • (NSArray*) messages;
  • (int) unreadMessages;

The current implementation I have is this:

Use case 1 : Initial Load

  1. When the view first appears the “loadFromServer” method is called. This populates the messages collection and raises an NSNotificationCenter event.
  2. The controller observes this event, and when received it populates the tableview

Use Case 2: New Message

  1. When a user clicks the “add” button a new view appears, they enter their message, hit send and then the view is dismissed.
  2. This calls the createMessage method on the model, which calls the API
  3. Once we have a response the model raises the NSNotificationCenter event
  4. Once again the MessageFeedController listens for this event and re-populates the table

Use Case 3: Push Message

  1. A push notification is received while the app is open, with the new message details
  2. The AppDelegate (or some other class) will call the addMessage method on the model, to add it to the collection
  3. Once again, assuming the MessageFeed view is open, it re-populates

In all three cases the MessageFeed view is updated. In addition to this a BadgeManager also listens to these events which has the responsibility of setting the app icon badge and the tabbar badge, in both cases the badge number relates to the number of unread messages.

It’s also possible that another view is open and is listening to these events, this view holds a summary of messages so needs to know when the collection changes.

Right, thanks for sticking with me, my question is: Does this seem like a valid use of NSNotificationCentre, or have I misused it?

One concern I have is that I’m not 100% sure what will happen if the messages collection changes half-way through re-populating the message table. The only time I could see this happening is if a push notification was received about a new message. In this case would the population of the table have to finish before acting upon the NSNotification anyway?

Thanks for your help

Dan.

  • 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-06-14T13:51:12+00:00Added an answer on June 14, 2026 at 1:51 pm

    In other words, you’re posting a notification whenever the message list is updated. That’s a perfectly valid use of NSNotificationCenter.

    Another option is to use Key-Value Observing.

    Your controller (and anyone else) can register as an observer to the “messages” property, and will be notified whenever that property changes. On the model side, you get KVO for free; simply calling a method named setMessages: will trigger the KVO change notification. You can also trigger the notification manually, and, if so desired, the KVO notification can include which indexes of the array have been added, removed, or changed.

    KVO is a standardized way to do these kinds of change notifications. It’s particularly important when implementing an OS X app using Cocoa Data Binding.

    NSNotificationCenter is more flexible in that you can bundle any additional info with each notification.

    It’s important to ensure that your messages list is only updated on the main thread, and that the messages list is never modified without also posting a corresponding change notification. Your controller should also take care to ignore these notifications whenever it is not the top-most view controller or not on screen. It’s not uncommon to register for change notifications in viewWillAppear: and unregister in viewWillDisappear:.

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

Sidebar

Related Questions

I am building a Web Application using asp.net (C#). I come from windows forms
I come from a .NET background and need to do a web project in
I'm just starting to dive into ASP.net MVC3. I come from a Django background.
I have a Crystal Report used in an ASP.NET web application that I've just
I come from Windows .Net forms development. This is a pretty basic/fundamental question. I'm
I come from a Java background and am getting more into .NET, what are
When making calls to a webservice from an asp.net web application, to avoid creating
I have one doubt here , I have one asp.net MVC web application and
I have an existing ASP.net 3.5 web application. This is tested and working in
I am sending email from my ASP.net web application. The mails are sending successfully

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.