Random number Generator in Cocoa application Google Objective-C SDK for iPhone development
Mar 21

I wanted to write a simple Console application in Cocoa. I followed the same old XCode approach of creating a project from the IDE. I started the project with Fundation Tool. Then the rest is to enter the following code into <the name you have given.m> which is the only class in that project. Its simple and good for making services and console applications. This also helps you to understand simple Number & Array manipulations with Objective-C style.

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSMutableArray *ar = [[NSMutableArray alloc] init];

NSNumber *n;

int i;

for (i=0; i<10; i++)

{

n  = [[NSNumber alloc] initWithInt:(i)];

[ar addObject:n];

}

for(i=0; i<10; i++)

{

NSNumber *newN = [ar objectAtIndex:i];

NSLog(@”Stored: %@”, newN);

}

NSLog(@”Number init %d\n”, i);

    // insert code here…

    NSLog(@”Hello, World from Muthu!”);

[ar release];

    [pool drain];

    return 0;

}

Download complete project: ArrayTest.zip


Leave a Reply