iOS Development - University of Cincinnati · OSX 10.7+ for iOS 5.0+ iOS device to test on. Basics...
Transcript of iOS Development - University of Cincinnati · OSX 10.7+ for iOS 5.0+ iOS device to test on. Basics...
iOS Development
Lots of market share
Java
Manufacturer control of OS
version
Large range of device spec
Declining popularity
Poor device performance
Accesible by any device
Limited APIs
Poor performance
iOS70% of all smartphones sold by Verizon and AT&T were
iPhones 1
90% of all mobile purchases are iPhones or iPads 2
Apple controls the market with 90% of all tablets sold being iPads 3
RequirementsApple computer (Mac)
$100/yr Personal Developer Account
OSX 10.7+ for iOS 5.0+
iOS device to test on
Basics of iOS
C
C++
Languages
Objective - C
Languages
UI framework for iPhone, iPod, and iPad
Cocoa Touch
Core Animation
Multitasking
Gesture Recognition
Cocoa Touch
UIKit Objects
NS* Objects
Cocoa Touch
3D
Low level
C or C++
OpenGL ES
Best Practices
Functions
In Objective - C, what we normally refer to as "functions" are now called messages. I usually call them "methods" because it encompasses both meanings.
Functions
In Objective - C, what we normally refer to as "functions" are now called messages. I usually call them "methods" because it encompasses both meanings.
Messages are declared and defined similar to functions
-(void)imageLoader:(NSString*)url;
Functions
In Objective - C, what we normally refer to as "functions" are now called messages. I usually call them "methods" because it encompasses both meanings.
Messages are declared and defined similar to functions
-(void)imageLoader:(NSString*)url;
Return type
Functions
In Objective - C, what we normally refer to as "functions" are now called messages. I usually call them "methods" because it encompasses both meanings.
Messages are declared and defined similar to functions
-(void)imageLoader:(NSString*)url;
Return type Name
Functions
In Objective - C, what we normally refer to as "functions" are now called messages. I usually call them "methods" because it encompasses both meanings.
Messages are declared and defined similar to functions
-(void)imageLoader:(NSString*)url;
Return type Name ParametersSeparated by ":"
Classes
Interface
Definitions of:● Methods● Private variables● Public variables● Delegates
Implementation
Does all of the work
Subclassing
You can subclass ALL of the UIKit and NS* objects
Highly recommend making your own objects if you are ever making a lot of custom methods
UIKit Hierarchy
Anatomy of a class
Interface
InterfaceClass
InterfaceClass
Private variables
InterfaceClass
Private variables
Public variables
InterfaceClass
Private variables
Public variables
Instance methods
InterfaceClass
Private variables
Public variables
Instance methods
Delegate
InterfaceClass
Private variables
Public variables
Instance methods
Delegate methods
Delegate
@propertyWhen an object is declared with @property, you must then use @synthesize in the implementation of your class.
@propertyWhen an object is declared with @property, you must then use @synthesize in the implementation of your class.
@synthesize creates GETTERs and SETTERs for the object
@propertyWhen an object is declared with @property, you must then use @synthesize in the implementation of your class.
@synthesize creates GETTERs and SETTERs for the object
Define the retention of the object in its @property definition. We'll talk about this later.
Implementation
Basic structure:
@synthesizeMethods
Deallocating
Delegates
Delegate Example@interface ImageLoader : NSObject
● Loads an image asynchronously● Sends a message �to its delegate when loaded● Declares method -(void)imageDidLoad
Delegate Example@interface ImageLoader : NSObject
● Loads an image asynchronously● Sends a message �to its delegate when loaded● Declares method -(void)imageDidLoad
@interface MyTableView : UITableViewController● Requests and loads data● Creates ImageLoader objects to load images async.● Is the ImageLoader object's delegate
Delegate ExampleInside MyTableView.m
ImageLoader *imgLoader = [[ImageLoader alloc] init];imgLoader.delegate = self;
Delegate ExampleInside MyTableView.m
ImageLoader *imgLoader = [[ImageLoader alloc] init];imgLoader.delegate = self;
...
-(void)imageDidLoad{ ...}
Delegate Example
MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad
Delegate Example
MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad
BUT
ImageLoader sends message imageDidLoad to MyTableView
Delegate Example
MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad
BUT
ImageLoader sends message imageDidLoad to MyTableView
BUT
MyTableView defines what -(void)imageDidLoad does
In many instances, a class will be its own delegate, e.g.:
A UITableViewController will be its own delegate to respond to table cell touches and scrolling
Memory Management
Device Memory
In developing apps, we have to bear in mind that we are working with very limited memory
512MB in most cases
Should develop to use at most half of that
Springboard uses lots of memory
PointersAll UI* and NS* objects are declared as pointers
PointersAll UI* and NS* objects are declared as pointers
NSArray *arr = [[NSArray alloc] init];
PointersAll UI* and NS* objects are declared as pointers
NSArray *arr = [[NSArray alloc] init];
Object
PointersAll UI* and NS* objects are declared as pointers
NSArray *arr = [[NSArray alloc] init];
Object AllocateMemory
PointersAll UI* and NS* objects are declared as pointers
NSArray *arr = [[NSArray alloc] init];
Object AllocateMemory
Initialization
PointersPointers have different states
retain, atomic, assign, copy, readonly, readwrite, strong
We should only really worry about retaining objects
PointersIf an object is retained, IT MUST BE RELEASED
If an object is instantiated is retained, it is the responsibility for the object's creator release it from memory or else it will remain in memory, causing a leak.
PointersIf an object is retained, IT MUST BE RELEASED
If an object is instantiated is retained, it is the responsibility for the object's creator release it from memory or else it will remain in memory, causing a leak.
Smaller objects won't cause big issues, but objects containing images or files will.
PointersIn iOS 5.0+ Apple introduced Automatic Reference Counting (ARM) which is a simple garbage collector (memory manager).
ARM manages objects and releases them.
PointersIn iOS 5.0+ Apple introduced Automatic Reference Counting (ARM) which is a simple garbage collector (memory manager).
ARM manages objects and releases them.
Limits your apps to iOS 5.0+ devices!
FrameworksHundreds of Open Source and paid frameworks for games, boilerplates, extensions, etc.
FrameworksHundreds of Open Source and paid frameworks for games, boilerplates, extensions, etc.
Apple prohibits the use of third-party libraries. Anything you use or create must be uncompiled.
More ResourcesProgramming iOS 5
O'Reilly Bookshttp://goo.gl/9LY6P
Apple's DocumentationXcode Docs
Sources
http://thenextweb.com/apple/2012/01/26/crazy-81-of-all-smartphones-sold-by-att-in-q4-were-iphones/1
http://gigaom.com/apple/study-apples-iphone-ipad-account-for-90-percent-of-mobile-purchases/2
http://daringfireball.net/2011/11/fun_with_numbers3