Upload
kenshin03
View
2.368
Download
0
Embed Size (px)
DESCRIPTION
Prepared for a small team sharing session. It was meant to be a 20 mins sharing to fellow developers who have otherwise had no exposure or experience to Objective-C or GUI programming.
Citation preview
iPhone SDK App Developmentpart 1: a very concise introduction
iPhone SDK
the iPhone OS and iPhone SDK dates back to 15+ years ago - both originate from NeXTStep
consists of Xcode, Interface Builder, Instruments, iPhone Simulator and more...
free download!
developer.apple.com/iphone
iPhone SDK Essential Facts
pre-requisites: Intel Mac, Mac OS X 10.5 Leopard, Obj C, OO programming concepts
patience, clean mindset
test on real devices & AppStore submission:
iPhone developer programme ($99 per year)
The iPhone OS
cocoa touch: UIKit framework (iphone specific), Foundation framework (wrappers to Core Foundation String, network, data structures, i18n.etc.)
media layer: Quartz (2d vector based drawing api), Core Animation, OpenGL, Audio, Video codecs
core services layer: Address Book, Core Foundation, Core Location, Security, SQLite, XML
core OS layer: Threading, IO, Memory, File Access, Networking
Objective-C: a quick look like C++/Java, but weirder
you don’t invoke object instances, you send messages to them indirectly
most of the OO and C++/Java concepts apply, like inheritance, polymorphism.etc.
some syntax difference to make you aware being in Obj-C or C space
java: calculator.sum(num1Value, num2Value, num3Value);
c++: calculator-> sum(num1Value, num2Value, num3Value);
obj-c: [calculator sum: num1Value withNum2:num2Value withNum3: num3Value]
A typical Objective C class
#import <Foundation/Foundation.h>
@interface SomeClass:SomeParentClass{ BOOL someBooleanValue; @private int someNumber;
$protected NSString someString;}
+ (id) alloc;+ (BOOL) anotherClassMethod;- (BOOL) returnSomeBooleanValueMethod;- (NSString) getSomeStringMethod;- (void) setValueOfSomeString: (NSString)someString;
@end
UIKit
Objective-C framework for event handling, drawing model, windows, views, and controls designed for iPhone
apps created in Xcode are linked to UIKit
runtime foundation for iPhone apps
UIWindow: space on a screen, like a picture frame
only covers the basics todayUIKit elements
UIView: base class of all visual objects. like a canvas.
View Controller handles multiple views, orientation changes, transitions.etc.
The First App
main.mHelloViewAppDelegate
<interface>
HelloViewAppDelegate<impl>
app that displays an empty view
main.mmain.m created by Xcode
hooks up obj-c framework
creates auto-release pool
main.mHelloViewAppDelegate
<interface>
HelloViewAppDelegate<impl>
HelloViewAppDelegate<impl>
app delegate class: main helper class for handling important life-cycle events
often the bridge between your app and system frameworks, e.g. CoreLocation
creates a UIView object with size of whole screen
add the view to main UIWindow object
make window visible
mark the objects for release upon exit
demo
Adding a bit of text
for convenience, create a MainView class extending from UIView, attach an UITextView object to it, then add it back to the main window object
main.mHelloViewAppDelegate
<interface>
HelloViewAppDelegate<impl>
MainView
HelloWoldAppDelegate.h
sets “Hello, World!” to its UITextView object
init a MainView object
attach it to the app delegate window object
demo
Adding orientation change support
create a ViewController class to do the heavy lifting
main.mControllerDemoAppDelegate
<interface>
ControllerDemoAppDelegate<impl>
ControlDemoViewController
init custom ViewController object
in this ViewController object, didRotateFromInterfaceOrientation() is overridden to change the text whenever the iPhone is rotated
demo
end of part i
next:
TabViewControllers, Interface Builder, Window Applications, Frameworks, AppStore submission and more