Using Notifications
The purpose of using a notification is to do exactly that, send a notification that some information / data, has changed. How this works is it will make the change and tell the notification the change has occurred, then when the data is needed it sends out the new information. Note: This is a new feature Apple added to the 4.0 software, so if your app targets lower than that, you will need to add script to tell you app to check which version they are using and to disable the code if it is below 4.0.
First start by creating a notification file (your .h file). File > New File > Mac OS X > C & C++ > Header File.
NotificationNames.h is a sample filename you could use to remind you that this is where the names of our notifications will be held. In this example I am going to use just one.

In this file all we write at the top is :
#define AllowanceDataWasChanged @"AllowanceDataWasChanged"
Now I go to my .m file where this data is being written, so the data I want access to. At the top of that file (or any file where I will do the same, I put:
#import "NotificationNames.h"
This means we will be able to access that files information. Now in this .m file, where the data save is occuring, I put the following code, which will alert our notification that a change is taking place. In my file I was calling:
-(void)saveClick:(id)sender{
// saved stuff goes here
}
So I added this code to the end of it:
[[NSNotificationCenter defaultCenter] postNotificationName: AllowanceDataWasChanged object:nil];
Now we need to go to the file where the information is being read, and where we need it to be read as data changes… Again at the begining of that .m file you need to add:
#import "NotificationNames.h"
Because I would like this data to be updated (it was a users name) as soon as there is a change in the name, I added this method to recognise / pick up the change sent to the notification:
-(void) updateViewData {
NSArray* array = [PListHelper getDataFromFile: kFilename];
if (array) {
nameLabel.text = [array objectAtIndex:0];
}
NSLog(@"calling update View"); // I added the log to see if it was being called.
}
Then we need to decide where we can / want to call that by using another method to see if there was a change:
-(void) allowanceDataWasChanged:(NSNotification*) notification {
[self updateViewData]; // method call that we wrote earlier
}
So there we are saying, if there is a change, load my updateViewData. Which – will load in those new / changed values. I also stuck this method call:
[self updateViewData];
In my
- (void)viewDidLoad {
}
method because we would like the new data to load if the view is loaded. Once you have the hang of that you can really add it into your code where you need to notify of data change.
Finally in your
-(void)viewDidLoad {
}
method you need to add the information that checks the notification, and if any changes were made:
[[NSNotificationCenter defaultCenter] removeObserver:self];
// register for notification by adding an observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(allowanceDataWasChanged:)
name:AllowanceDataWasChanged
object:nil];
It’s an amazingly useful thing to know – thanks to Shaun Austin (@irvtheswirv) for talking me through it.
… Waiting For Review
Documenting the process of starting app development seems to be as difficult as the actual app development. I started a new blog, where I would put code snippets I was working on, and had every intention of noting down my findings as they happened, but I found as I was learning I couldn’t stop long enough to write it down. I realise how valuable this process is and I am taking the time to look back on what has happened during these whirlwind few weeks.
Summer 2009
I had started looking at iPhone development summer of 2009. I had the Apress book, ‘Beginning iPhone Development‘, and I started working through the chapters. The trouble was that I really had no context of why and how it was actually working, which meant I wouldn’t be very likely to code my own apps. Anyway, from that point forward work started up again and I had to put it to one side because I could see the dedication it would take.

Some of the notes I took in my notebook while learning the languages.
March 2010
By the time Easter holidays came round I had decided that I wanted to start back getting to learn code. I had been thinking of iPhone development on and off through out the year and the time was right. So this time I planned it all a bit better. I would start off with learning the absolute basics, C during March.
I spent 4 weeks of March working through Apress ‘Learn C on the Mac‘, and an old C book I found from when I had first studied it years back (Teach Yourself C). I made hundreds of pages of notes in the process and worked through exercises from both books. I think some concepts made sense quite quickly from what I had recognised from earlier. I was now able to move on to ‘Learn Objective-C on the Mac’.
While I was reading the coding books I was also spending time reading about User Interface design. As important and essential the code is, no app will sell if it is unusable, or takes no notice of UI principles. along with that I was reading some more generic information about app planning. This was one planning phase I wrote out:
1 – Overall UI. This is the generic layout of the items for the features / functions of your app.
2 – Architecting. (application) This phase you are building all the elements so that they will work and are connected.
3 – User Testing. Testing phase of the app, though I would say that this phase really needs to be done throughout the whole process, continually as you try and check new things.
4 – Graphic Design. Make it slick~
April 2010
I spent an intense 2 weeks of Easter holiday reading and doing the exercises for Obj-C. I made a few of the sample apps as demonstrated, and I tried to modify them and add things to them to stretch what they were showing me.
By this point I was so excited that I was finding it increasingly harder to focus, I wanted to read faster than my eyes would let me because I knew the next step would be working through the first book I initially got – the iPhone Development book… I began sticking notes all over my computer and study of all the little reminders of things to do when developing, and conventions to follow as well as designing / sketching out app ideas.
One thing I hadn’t realised was that sketching out an app isn’t always as representative as I thought it would be. There was an app I had sketched out and when I went to just create a mock up in Interface Builder I realised that several things just wouldn’t be appropriate for touch, or that things could be done far more efficiently through touch. Mapping out the app while constantly questioning the touch factor of it is essential.

An image from Snippets, the code collecting program I have started to use to organise code.
I have also started collecting code snippets that I find useful and that I know I will reuse. I have tried a few applications for mac but I found Snippets (shown above) suited me best.
May 2010
By the time May came round, I had tried and experimented with a few chunks of code from the books and from the Internet. This led to me wanting to go through the entire process of app – start to finish. Planing, coding and submitting.
Lil Tweet
The lil tweet app was initially created to just be a quick tweeting app, so I would not even need to look at twitter, I could launch the app and send a tweet really quickly. As I was working on it I wondered what it would be like if everyone was sharing one account, so I changed the app to reflect it no longer it being an app that I tweet from – but an app that everyone can tweet from.
I spent about a week coding and testing the Lil Tweet app, and from that time there was design issues, making the background image in Photoshop to match up where I was going to put the components.
I made the app initially just with the tweet field, and when it was looked at and tried, I was asked how can they then see the tweet they sent, so i spent time working on adding that you can then launch viewing the twitter feed you have just added to. From there I realised that it would be very difficult to use if you didn’t have a character count down. This was the most difficult aspect of the app. I had so many errors and troubles to figure out how to get it to work. I swapped textFields with texeViews and Labels and back again…. This took up most of the entire time of the app development.
From there I worked on getting everything to Apple standard for submission, the images, screen shots, icons etc all had to be created to a set standard. This was then ready for submission which actually took me an entire day to do. I kept getting the certificates wrong and error messages about the certificates not matching were bugging me all day. Finally by the evening, I deleted all certificates and profiles and proisioning and went for it from the start of the process. This finally worked. *phews* Leaving me Waiting For Review…
Today (May 24 2010), 7 days after submission, the Lil Tweet app was approved and is now for sale.
The Future
It has been an amazing journey and I am so glad I stuck with it. Since waiting for review, I started the Apps and Hats app for the show, and that has gone in for submission today. I hope I am as lucky and I get approved as quickly because I would love to launch it with the show on Friday. Just started planning for my first iPad application…





![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=f6db76b2-76d3-4810-a248-79e4bf02d9fd)