Objective-C Challenge

I have started learning objective-c.  Coming from C# background, things are not straight forward, here is one of the challenge i completed today i.e. to subtract birthday date with current date and displaying results in second.


I am learning objective-c using big nerd ranch guide.  Turning out to be a good book


//  main.m

//  TimeAfterTime


//  Created by Sumit Gupta on 12/07/12.

//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.



#import <Foundation/Foundation.h>


int main(int argc, const char * argv[])



    @autoreleasepool {


        NSDateComponents *comps = [[NSDateComponents alloc]init];

        [comps setYear:1981];

        [comps setMonth:3];

        [comps setDay:21];


        NSCalendar *g = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSDate *dateOfBirth = [g dateFromComponents:comps];


        NSDate *currentDate = [NSDate date];

        double d = [currentDate timeIntervalSinceDate:dateOfBirth];



        NSLog(@”difference is %f”,d );





    return 0;




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s