iOS Programming Tennessee Valley Apple Developers        Saturday CodeJam        February 12, 2011
Our First Project:      Hello, iPhone!
Create a Project1. Start Xcode2. Create a new project3. Under “iOS > Application”4. Choose “Window-Based Application” with...
Console Positioning• Note: to bring the console to the front  when you’re launching a program in Xcode,  select “Xcode Pre...
Xcode Project Window
Groups and Files pane         •   Classes – contains project files that             are Objective-C source code files       ...
Detail View•   Displays detailed information about any of the    items selected in the Groups and Files pane
Editor Pane•   Displays the contents of any editable file    selected in the groups and Files or detail pane
Name Conventions• Project names begin with an upper case  letter• Class names begin with an upper case letter• variable, p...
A Look at Our          ProgramUnderstanding the Relationship of our Components
main.m#import <UIKit/UIKit.h>int main(int argc, char *argv[]) {    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] i...
Core of main.m            int UIApplicationMain (                int argc,                char *argv[],                NSS...
Info.plist
Interface Builder• Open your “Resources” folder in the  Groups and Files pane, and double click on  “Hello_WorldViewContro...
MainWindow.xib
View Controller
Hello_WorldViewController.xib
Nib File• Every nib file starts with the same two icons:  • File’s Owner – the object that loaded the    nib file from disk,...
Hello_WorldViewController.xib• View – an instance of the UIView class.  Each “screen” of an iOS application is  managed by...
Adding a Label to our View•   Select the Library window. If it is not present on the screen,    you can pull it forward by...
What just Happened?• When the program launched, the main()  function was kicked off• main() loaded a UIApplication object,...
UIApplication• UIApplication is implemented as a Singleton• A Singleton is a design pattern where only  one instance of th...
UIApplication Tasks•   Getting the Application Instance•   Getting Application Windows•   Setting and getting the Applicat...
When your App Starts• Standard lifecycle for any application• Hooks for your specific application  customization
iOS Application Lifecycle
App Delegate Interface         File• HelloWorldAppDelegate, which is a subclass of  NSObject, adopts the UIApplicationDele...
Where our code begins                   Called by the  (code omitted)     runtime
Objective-C: A Review•   Objective-C is a superset of C    •   Any C you know applies    •   All the standard C libraries ...
Smalltalk Heritage• Classes• Objects• Think in terms of messages • C functions look like NSLog() • Objective-C methods loo...
View and View Controller  •   Each app has a single window  •   Think of every screen filled with stuff as being a      vie...
MVC       ControllerView                Model
Interface Builder• Go back to Interface Builder, pull up the  Inspector for the Label in your UIView, and  play with the d...
Finishing Touches•   Let’s add an icon to our app to replace the boring    white icon that has shown up on our simulator s...
Inserting the Icon into       your project• Right click on the “Resources” folder in  Xcode, and select “Add > Existing Fi...
Adding an Icon...                       •   Check “Copy items                           into destination                  ...
Adding the icon...• Now we need to tell the compiler which  file in our Resources folder is our icon file• Select the “Hello...
Adding the icon...•   Click “Build and Run”•   Stop your app by clicking on the black button in the simulator to see your ...
Icon Specifications• Apple has published guidelines for handling  icons for iOS apps• These guidelines can be found at:  ht...
Icon Specs Summary
Contents ofHello_World-Info.plist
iOS programming
Upcoming SlideShare
Loading in...5
×

iOS programming

2,500

Published on

Introduction to iOS Programming

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,500
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
141
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • iOS programming

    1. 1. iOS Programming Tennessee Valley Apple Developers Saturday CodeJam February 12, 2011
    2. 2. Our First Project: Hello, iPhone!
    3. 3. Create a Project1. Start Xcode2. Create a new project3. Under “iOS > Application”4. Choose “Window-Based Application” with iPhone selected and Core Data unchecked5. Name it “HelloWorld” and choose a location in your file system to save6. Build and Go
    4. 4. Console Positioning• Note: to bring the console to the front when you’re launching a program in Xcode, select “Xcode Preferences > Debugging”• Pick “On Start: Show Console”
    5. 5. Xcode Project Window
    6. 6. Groups and Files pane • Classes – contains project files that are Objective-C source code files • Other Sources – contains project files that are not source code • Resources – non-code files that are part of your application • Frameworks – various libraries that are part of the Cocoa framework, or any external frameworks, that your application is using • Products – contains your compiled application files
    7. 7. Detail View• Displays detailed information about any of the items selected in the Groups and Files pane
    8. 8. Editor Pane• Displays the contents of any editable file selected in the groups and Files or detail pane
    9. 9. Name Conventions• Project names begin with an upper case letter• Class names begin with an upper case letter• variable, property and method names begin with a lower case letter• CamelCase is used for all naming conventions
    10. 10. A Look at Our ProgramUnderstanding the Relationship of our Components
    11. 11. main.m#import <UIKit/UIKit.h>int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal;} • Your program’s execution begins here • There is usually no reason for you to modify anything in main.m
    12. 12. Core of main.m int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName );• principalClassName - nil gives you UIApplication; you can also specify UIApplication or a subclass of - Note: this is your Nib’s file owner• delegateClassName - nil to load delegate from Nib; you can also specify an Application Delegate
    13. 13. Info.plist
    14. 14. Interface Builder• Open your “Resources” folder in the Groups and Files pane, and double click on “Hello_WorldViewController.xib”• This will launch Interface Builder• Select the “MainWindow.xib” file
    15. 15. MainWindow.xib
    16. 16. View Controller
    17. 17. Hello_WorldViewController.xib
    18. 18. Nib File• Every nib file starts with the same two icons: • File’s Owner – the object that loaded the nib file from disk, and “owns” the loaded copy of the nib file • First Responder – the object with which the user is currently interacting; the actual object that the “First Responder” represents changes as the user interacts with the program
    19. 19. Hello_WorldViewController.xib• View – an instance of the UIView class. Each “screen” of an iOS application is managed by a UIView object.• The Views get swapped into and out of the application’s main Window as the user navigates through the components of the application
    20. 20. Adding a Label to our View• Select the Library window. If it is not present on the screen, you can pull it forward by selecting “Tools > Library”, or using the keyboard shortcut Command-Shift-L• Find a Label object, and drag and drop it onto your View object• This adds an instance of UILabel as a subview to our application’s main view• Expand our label to span the width of the view, within the guidelines• Double click on the label and change the text from “Label” to “Hello World”• Save IB, toggle back to Xcode and Build and Run.
    21. 21. What just Happened?• When the program launched, the main() function was kicked off• main() loaded a UIApplication object, which basically represents the application itself• The UIApplication object in turn gets the specified UIApplicationDelegate object, which for our application is a Hello_WorldAppDelegate object
    22. 22. UIApplication• UIApplication is implemented as a Singleton• A Singleton is a design pattern where only one instance of the class is in existence for the application
    23. 23. UIApplication Tasks• Getting the Application Instance• Getting Application Windows• Setting and getting the Application Delegate• Controlling Application Behavior• Opening a URL Resource• Managing Status Bar Orientation• Responding to a Change in Active Status• Controlling Application Appearance• Handling Remote Notification
    24. 24. When your App Starts• Standard lifecycle for any application• Hooks for your specific application customization
    25. 25. iOS Application Lifecycle
    26. 26. App Delegate Interface File• HelloWorldAppDelegate, which is a subclass of NSObject, adopts the UIApplicationDelegate protocol
    27. 27. Where our code begins Called by the (code omitted) runtime
    28. 28. Objective-C: A Review• Objective-C is a superset of C • Any C you know applies • All the standard C libraries are here• Small set of extensions • @class - a ‘compiler directive’ • [object doSomething] - message sending• Objects are reference counted
    29. 29. Smalltalk Heritage• Classes• Objects• Think in terms of messages • C functions look like NSLog() • Objective-C methods look like [objectName doThis]
    30. 30. View and View Controller • Each app has a single window • Think of every screen filled with stuff as being a view • We move from screen to screen by replacing one view with another • Each screen is managed by a View Controller • The initially visible view controller’s view is instantiated somehow at startup, and then it is usually added to the window as its subview
    31. 31. MVC ControllerView Model
    32. 32. Interface Builder• Go back to Interface Builder, pull up the Inspector for the Label in your UIView, and play with the different attributes
    33. 33. Finishing Touches• Let’s add an icon to our app to replace the boring white icon that has shown up on our simulator screen.• Download the icon located at: https://github.com/lhridley/AppleDev/blob/master/ Hello_World/icon.png to your desktop.• If you don’t have a GitHub account, you can create one for free
    34. 34. Inserting the Icon into your project• Right click on the “Resources” folder in Xcode, and select “Add > Existing Files…”• Navigate to your Desktop, select the icon file and click the “Add” button
    35. 35. Adding an Icon... • Check “Copy items into destination group’s folder” at the top • Make sure you check “Hello_World” in the Add To Targets window • Click the “Add” buttonYou should now see the icon file in yourResources folder
    36. 36. Adding the icon...• Now we need to tell the compiler which file in our Resources folder is our icon file• Select the “Hello_World-Info.plist file• Change the value of the Icon key to icon.png
    37. 37. Adding the icon...• Click “Build and Run”• Stop your app by clicking on the black button in the simulator to see your icon• By default, Apple adds the curved edges and “glass” effect to the icon images
    38. 38. Icon Specifications• Apple has published guidelines for handling icons for iOS apps• These guidelines can be found at: https://developer.apple.com/library/ios/#qa/ qa2010/qa1686.html
    39. 39. Icon Specs Summary
    40. 40. Contents ofHello_World-Info.plist
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×