Graphics Programs Reference
In-Depth Information
Click on main.m to open it in the editor area, and you'll see that some code has been
written for you - most notably, a main function that is the entry point of any C or
Objective-C application.
Time to put your knowledge of Objective-C basics to the test. Delete the line of code that
NSLog s “Hello, World!” and replace it with lines that create and destroy an instance of
the Objective-C class NSMutableArray .
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
// Create a mutable array object, store its address in items variable
NSMutableArray *items = [[NSMutableArray alloc] init];
// Destroy the array pointed to by items
items = nil;
}
return 0;
}
Once you have an instance of NSMutableArray , you can send it messages, like ad-
dObject: and insertObject:atIndex: . In this code, the receiver is the items
variable that points at the newly instantiated NSMutableArray . Add a few strings to
the array instance.
int main (int argc, const char * argv[])
{
@autoreleasepool {
// Create a mutable array object, store its address in items variable
NSMutableArray *items = [[NSMutableArray alloc] init];
 
Search WWH ::




Custom Search