Xcode

advertisement
Using Xcode
A Beginner’s Tutorial
Erin Green
• This tutorial will walk you through Xcode, a
software development tool for Apple’s iOS
applications
– We will explore its different parts and their
functions
– This tutorial will teach you how to use Xcode, but
not how to build an app.
• To build an app, you need to know Objective-C.
Why should I learn this?
• Learning the ins and outs of Xcode will help
you to be more comfortable if you decide to
attempt Objective-C later.
• Lots of libraries are creating apps to promote
themselves and connect with their patrons.
Before We Begin…
You need a computer running
Mac OS 10.6 or better
A familiarity with programming
helps
Download the Xcode installer
from the Apple app store
The current version
available is Xcode 4
It’s free!
Open the .dmg file and install to
your hard drive
Useful Terms
• Objective-C: the programming language used
to write iOS applications, based on C and
using object oriented programming methods
• Object: a collection of code with its data and
ways to manipulate that data
Useful Terms
• View: how your program presents
information to the user
• Model: how your data is represented inside of
your application
– Like a card catalog behind the scenes of your app
– A ‘model object’ would be an individual card
Let’s Start a New Project
Open Xcode in your
applications folder
Choose File 
New  New Project
Choose your app template
App Templates
Master-Detail App:
Like the iOS email
app, works on
parent/child
relationships
Open GL: allows for
3D hardware and
animation timers.
Good for games.
Page-Based: For
apps with 2 views,
such as the Maps
app. 1 main page
and 1 details/info
page
Single View: A single
screen. Fairly
simple apps with
the views remaining
on one
”background”
App Templates, Pt 2
Tabbed: Like the iPod app,
with lots of different ways
to view the same
database items
Utility: Like the
weather app, a main
view and a
configuration view
Empty: You build
everything from
scratch
Starting an App
Choose the name you want
for your app
Click ‘Next’
Choose a folder in which to
save your app
Finally, choose your device
Writing a universal iOS
app is more difficult
than writing for just
one device
This is what your screen looks like
now….
The main parts we’ll be focusing
on…
1. Navigator Panel
2. Inspector Panel
3. Libraries
Navigator Panel
The Classes folder contains two
objects:
- The App Delegate
- The View Controller
The extensions:
- .h = header, defines object
- .m= main/body
-.xib= XML interface builder
The App Delegate
• Handles starting and ending your app
• Serves as a go-between between iOS and your
app
– Hands off control to your code after starting
The View Controller
• Handles everything that shows up on screen
• Handles all the info that the onscreen objects
need to display themselves
• Translates between the view and the model
• Responds to user input and uses that to
change model data
– Responsible for updating view from the model
To help visualize…
From developer.apple.com
XML Interface Builder
This is where you lay out
graphic views
The view controller knows
how to talk to the objects
that have been created
here
Lots of formatting options
Supporting Files, Pt. 1
These are system files
.plist = property list
Appname-Info.plist =
contains info about your
app for the iOS. It is an
XML file that includes the
options you put on your
app (which device, etc.)
InfoPlist.strings = helps to
internationalize your app
-Language translation
cues
-.strings is any text
Supporting Files, Pt. 2
Main.m = low level. Starts
app and gives to the App
Delegate. Never change
this file.
.pch = pre-compiled
header
Appname-Prefix.pch =
generated by the system
to speed up builds
Frameworks
Frameworks contains a lot of already
written code provided by the system
- A library of code bits
- Related to the Libraries
menu on the right of Xcode
UIKit = contains code for everything
that interfaces with the user (views)
Foundation = alll the components
used to build the model
CoreGraphics = handles drawing on
the screen
Products
Where built apps are
stored
Inspector Panel
• This area contains
utilities panels that let
you change properties
of your app’s view
objects, like:
•
•
•
•
Colors
Sizes
Images
Button actions
Libraries
• Different goodies
depending on which icon
you click
– From left to right:
•
•
•
•
File templates
Code snippets
View Objects
Media/Images
Tips and Tricks
• If you’re unsure about what a piece of code
does, you can get help from Xcode:
– Hold ‘Option’ and click on the mystery code piece
– A “quick help” balloon will appear with a
definition
Tips and Tricks
You can also click
in the upper right corner
on the Inspector Panel to get the same help.
While you’re coding, Xcode will often begin to
auto-complete your code.
Select what you want from the list it gives.
It’s a good time-saver.
References
For additional help, you can try:
Mark, D., & LaMarche, J. (2009). Beginning
iPhone 3 development: Exploring the iPhone
SDK. Berkeley, CA: Apress.
Or
The Apple Developer web site at
http://developer.apple.com/
Now you’re ready to begin experimenting in
Objective-C using Xcode. Have fun!
Download