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

  • SEARCH
  • Home
  • 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 8332715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:48:05+00:00 2026-06-09T02:48:05+00:00

I’m working through a challenge in Objective-C Programming, The Big Nerd Ranch Guide, and

  • 0

I’m working through a challenge in Objective-C Programming, The Big Nerd Ranch Guide, and I’m a little flummoxed by one of the challenges.

Use two instances of NSDate to figure out how many seconds you have been alive. Hint: here is how you create a new date object from the year, month, etc.:

So I need to the difference between now and my date of birth in seconds. Sounds good. Then the hint shows up:

@autoreleasepool {
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setYear:1981];
    [comps setMonth:7];
    [comps setDay:12];
    [comps setHour:1];
    [comps setMinute:55];
    [comps setSecond:33];

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

    NSDate *dateOfBirth = [g dateFromComponents:comps];

The first issue is I don’t understand what *g is meant to be. I know it’s a pointer to an NSCalendar object. But why do we need it? And what is g meant to stand for?

The sample code then uses the g variable to grab a date. In another language, this would be as easy as DateDiff(dateOne, dateTwo, interval). I’m not clear on why the Calendar object is necessary in the first place, and why we have to create date components to feed the object.

This is all new to me, and I’ve worked with dynamic languages in the past. So a “dummies” like explanation would be great!

  • 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-09T02:48:07+00:00Added an answer on June 9, 2026 at 2:48 am

    The sample code then uses the g variable to grab a date. In another language, this would be as easy as DateDiff(dateOne, dateTwo, interval). I’m not clear on why the Calendar object is necessary in the first place, and why we have to create date components to feed the object.

    I’m not an Objective-C programmer, but I know a bit about date/time APIs.

    In order to specify your birth date/time, you’re giving a year of 1981, a month of 7 etc. What does a year of 1981 mean? To you, it may mean about 31 years ago… but to someone using a different calendar system, it could mean something entirely different. Converting from “year/month/day etc” to “point in time” is a bit like converting from a string to an integer: does “10” mean ten, or sixteen? It all depends on your frame of reference (the base, in this case – the calendar system in the date case).

    The calendar – initialized as a Gregorian calendar – takes those date components and is able to give you back an NSDate which is a sort of “absolute” value in time.

    As for computing the difference between two NSDate values – I suspect there’s a member which gives you something like “seconds since the Unix epoch” (or possible milliseconds). So take that from both dates (your birth and “now”), subtract one from the other, and you’ll get the elapsed number of seconds (or milliseconds) between the two.

    EDIT: In fact, the timeIntervalSinceNow function is probably the one you want, once you’ve got your birth date.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker

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.