Search code examples
iphoneobjective-calphabet

Is there an easy way to programmatically get the alphabet?


I want an NSArray/NSMutableArray containing all the letters of the alphabet. There must be a quick and easy way, better than typing them all out. For example in PHP:

foreach(range('A','Z') as $i) $alphabet[]=$i;

Solution

  • There's no quicker way than typing them all out, unless you cut and paste my handy reference from below!

    "abcdefghijklmnopqrstuvwxyz"


    For the sake of it, here's a longer way.

    for (char a = 'a'; a <= 'z'; a++)
    {
      [myArray addObject:[NSString stringWithFormat:@"%c", a]];
    }