iOS programming
Upcoming SlideShare
Loading in...5
×
 

iOS programming

on

  • 2,457 views

Introduction to iOS Programming

Introduction to iOS Programming

Statistics

Views

Total Views
2,457
Views on SlideShare
2,449
Embed Views
8

Actions

Likes
5
Downloads
113
Comments
0

1 Embed 8

http://www.techgig.com 8

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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 iOS programming Presentation Transcript

  • 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 iPhone selected and Core Data unchecked5. Name it “HelloWorld” and choose a location in your file system to save6. Build and Go
  • 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”
  • Xcode Project Window
  • 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
  • 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, property and method names begin with a lower case letter• CamelCase is used for all naming conventions
  • 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] 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
  • 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
  • Info.plist
  • 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
  • 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, 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
  • 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
  • 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.
  • 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
  • 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
  • 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
  • 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 UIApplicationDelegate protocol
  • 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 are here• Small set of extensions • @class - a ‘compiler directive’ • [object doSomething] - message sending• Objects are reference counted
  • Smalltalk Heritage• Classes• Objects• Think in terms of messages • C functions look like NSLog() • Objective-C methods look like [objectName doThis]
  • 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
  • MVC ControllerView Model
  • Interface Builder• Go back to Interface Builder, pull up the Inspector for the Label in your UIView, and play with the different attributes
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Icon Specs Summary
  • Contents ofHello_World-Info.plist