Simple Age-Check in iPhone SDK

For a recent project, I needed to get the user’s age within my iPhone application. It was a simple “how old are you?” question. Here’s the quick snippet for how I went about getting that info.

What you’ll already need is either:

  1. a UIPickerView object created, initialized, and set in your view controller; or
  2. a UIPickerView created and attached using Interface Builder.

In this example, I’m using the variable name pickerView for my UIPickerView object.

That’s it! How accurate it is depends entirely on Apple’s implementation. You can also do the same for any of the calendar values listed in the NSLocale documentation.