Twitter: raymondcamden


Address: Lafayette, LA, USA

My first native iOS app - Death Clock

03-25-2014 3,954 views Mobile 13 Comments

A few days ago I returned from a week of Objective-C and iOS training. I wanted to build an app on my own just to see what I could do and how comfortable I felt with the technology away from the Nerd Ranch. While it isn't pretty and the code is probably wrong in multiple ways, I've been able to create a native version of the Death Clock.

I used a UINavigationController to handle my views. I like the simple push, pop architecture and that you can disable the navigation bar. I wanted a "full screen" view for my application so that was important. The application is split into two sections. The initial screen is a simple config.

For the application I decided to only use birthdate and not gender. I wish there was a bit more control over the data picker widget. It seems huge to me. I spent about 30 seconds on the button so pardon the low tech look. The application also makes use of NSUserDefaults to record your birthdate for future loads. Want to see what this screen looks like? Check it out:

//
//  RKCConfigViewController.m
//  Death Clock
//
//  Created by Raymond Camden on 3/24/14.
//  Copyright (c) 2014 Raymond Camden. All rights reserved.
//

#import "RKCConfigViewController.h"
#import "RKCDeathClockViewController.h"

@interface RKCConfigViewController()

@property (nonatomic, weak) IBOutlet UIDatePicker *birthdayPicker;
@property (nonatomic, weak) IBOutlet UIButton *startDeathClock;
@property (nonatomic, strong) NSDate *birthday;

@end

@implementation RKCConfigViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        //check for default
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSDate *defaultBD = [defaults objectForKey:@"Birthday"];
        NSLog(@"%@", defaultBD);
        if(defaultBD) _birthday = defaultBD;
        else _birthday = [[NSDate alloc] init];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //no times, just m/d/y
    _birthdayPicker.datePickerMode = UIDatePickerModeDate;
    _birthdayPicker.date = _birthday;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //you weren't born in the future
    self.birthdayPicker.maximumDate = [[NSDate alloc] init];
    //set an initial data
    _birthday = [[NSDate alloc] init];
}

- (IBAction)setBirthDay:(id)sender
{
    _birthday = self.birthdayPicker.date;
    NSLog(@"Set bday for %@", self.birthday);

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:_birthday forKey:@"Birthday"];

}

- (IBAction)startDeathClock:(id)sender
{
    NSLog(@"CLICK ME BABY");
    RKCDeathClockViewController *dvc = [[RKCDeathClockViewController alloc] init];
    dvc.birthday = _birthday;
    [self.navigationController pushViewController:dvc animated:NO];
}

@end

The second view is the actual counter. This isn't terribly exciting. I've got the actual death date and then the number of seconds.

And that's it. Want to see all the code? I created a new GitHub repo so I could store my examples. To be clear, do not consider this anything near "good" iOS programming. I just wanted to share.

Objective-C Examples

Later this week I think I may try to get this into the App Store. I figure I don't have much chance of it being accepted, but it can't hurt, right?

13 Comments

  • Commented on 03-25-2014 at 10:45 AM
    Ah, the more things change, the more they stay the same.
  • Dom Howard #
    Commented on 03-25-2014 at 11:12 AM
    As long as it's not a fart app, you'll be fine
  • Commented on 03-25-2014 at 11:53 AM
    I have a similar app that I released for Android. It has a sea of one-star reviews, mostly from people who say it scares the crap out of them :)

    http://www.amazon.com/gp/product/B005ZIOBRU
  • Commented on 03-25-2014 at 11:59 AM
    John, back when I created Death Clock (originally it was a Perl script, than ColdFusion, than JavaScript), I used to get such letters/reviews all the time. People can't seem to separate a web site from reality. ;)
  • Commented on 03-26-2014 at 5:06 AM
    Not sure I have a use for it but cool.
  • Jay Van Voast #
    Commented on 03-26-2014 at 9:04 AM
    Where was the Objective-C and iOS training? And was it worth it?
  • Commented on 03-26-2014 at 9:11 AM
    @Jay: Please see the first link in the blog article. I wrote a lengthy review of the course.
  • Jay Van Voast #
    Commented on 03-26-2014 at 9:20 AM
    Thanks Ray I must have missed that post. Thanks again for all you do!
  • Commented on 03-26-2014 at 1:56 PM
    Why didn't want the navigation controller to animate?
  • Commented on 03-26-2014 at 1:57 PM
    There was a bug where when the black counter screen came in, it was visible "beneath" the white view. I fixed that bug and it animates now.
  • Commented on 03-26-2014 at 2:05 PM
    Gotcha. There are some definite issues w/ animating a nav controller for custom/transparent backgrounds. I have some code I'm going to push out as an example to show an easy way around it, if I can get a moment to breathe.

    Also, you might want to call synchronize on your defaults:
    [defaults synchronize];

    That will write the values immediately. It is called at regular intervals anyway but in the event you wanted the RKCDeathClockViewController to load the value vs passing it in, you'd want to sync it immediately so the value is saved by time it is read.
  • Commented on 03-26-2014 at 2:07 PM
    Cool tips - thanks! Added and pushed.
  • Commented on 03-26-2014 at 2:29 PM
    No prob man. I'm steadily learning more and more since I'm doing this 100% of the time at work now. It is time for me to start blogging/sharing, which sparks convo and helps spur more growth.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty