Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 12.5 ('Yosemite')
Instant purchase and download via GumRoad!

FEATURE

In-App Notifications

A system where your code can talk to itself

Issue: 12.5 (September/October 2014)
Author: Sam Rowlands
Author Bio: Sam is the codemancer behind Ohanaware Software.
Article Description: No description available.
Article Length (in bytes): 16,665
Starting Page Number: 16
Article Number: 12504
Resource File(s):

Download Icon 12504.zip Updated: 2014-09-05 0:20:29
Related Link(s): None

Excerpt of article text...

Today I'm going to talk about in-app notifications. I don't mean user interface dialogs that pop-up to say something has been done, or the ones that appear when you've received a message. I'm going to explain an internal communication process that's used with Objective-C applications, and how this technique can be used to improve Xojo-made apps. It works wonderfully with threads!

In the diagram shown in Figure 1, you can see that I have three objects on a window: a thread, progress bar, and a timer. Now in order for the thread to update the progress bar, there has to be a timer which regularly polls the thread to find out its progress, and then it updates the progress bar. If the thread tries to directly update the progress bar, that will raise an exception.

How Do Notifications Help?

In Figure 2, you can see that the timer is gone, and instead we have a NotificationManager object. The notification manager acts as a bridge between the thread and the progress bar. The progress bar registers itself with the NotificationManager as a listener, then any time the Thread sends a message to the NotificationManager, the message then gets forwarded to the Progress Bar.

The real power comes when you want to expand the process. For instance, you may have another window with another progress bar or even some code in the app that updates the dock icon. By also registering these objects for the messages, they'll automagically receive them when the thread sends the messages!

By removing the direct connection from the thread and the progress bar, we can easily get other objects to listen for the message, and if those objects no longer exist (say you close the second window) they no longer receive the messages—and you don't even have to write any extra code to handle any errors.

...End of Excerpt. Please purchase the magazine to read the full article.