Instructions 1. Open xCode 2. File -> New Project 3. Start a new View based iPhone Project. The type...

Post on 19-Dec-2015

218 views 2 download

transcript

Instructions

1. Open xCode 2. File -> New Project 3. Start a new View based iPhone Project. The type of project you create really doesn’t matter for this exercise since we will only be programming a for loop to print and not creating any User Interface. 4. Call the project iCodeBlogCounter 5. After saving the project you will be confronted with a screen looking something like this.

xcodefirstscreen:

If you look in the top left hand corner you will see a folder called Classes. If you click the little black triangle to the left of the folder you will see what is included in the classes folder. In there you should see a class called iCodeBlogCounterAppDelegate.m. This is the file we will be working with. Click on it and you will see its contents appear in the editor window.

GroupsandfilescloseupWe will be working with the – ((void)applicationDidFinishLaunching:(UIApplication *)application method. This method is called when the application finished launching. We will be entering some very simple code that will simple count from 0 to 99 and print the numbers in the terminal window. Here is what the method should look like:

The code here is:

for(int i = 0; i < 100; i++){ NSLog(@"The current number is: %d", i);}

That is all we need to do for this app. Now time to see it in action. To bring up the terminal window hit SHIFT + APPLE + R, this should bring up a blank window with maybe a line of text in it. Now click Build and Run or hit Apple + R. The terminal windows should say “The current number is 0″ all the way to “The current is 99″. Here is a screenshot of my window.

1. Open xCode 2. File -> New Project 3. Start a new View based iPhone Project. The type of project you create really doesn’t matter for this exercise since we will only be programming a for loop to print and not creating any User Interface. 4. Call the project iCodeBlogGetURLText 5. Once the project is open go into the iCodeBlogURLTextAppDelegate.m file. 6. Add this code to the - (void)applicationDidFinishLaunching:(UIApplication *)application method

NSString *myURLString = @"http://losectrl-gaincommand.com/iCodeBlogHelper/Tutorial2/iCodeBlog.txt"; NSURL *myURL = [NSURL URLWithString:myURLString]; NSString *myString = [[NSString alloc] stringWithContentsofURL:myURL];

NSLog(@"The string from the internet is: %@", myString);

7. If you bring up the terminal window and Build and Run the App. You should see:

Instructions

1. Go back to the code we just wrote. 2. Erase the 4 lines of code we wrote and replace it with this line:

NSLog(@"The string from the internet is: %@", [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://losectrl-gaincommand.com/iCodeBlogHelper/Tutorial2/iCodeBlog.txt"]]);

3. Running the application again should have the same output. 4. Here is a a breakdown of out new line of code.