58
iOS Development

iOS Development - University of Cincinnati · 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,

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: iOS Development - University of Cincinnati · 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,

iOS Development

Page 2: iOS Development - University of Cincinnati · 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,

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

Page 3: iOS Development - University of Cincinnati · 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,

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

Page 4: iOS Development - University of Cincinnati · 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,

RequirementsApple computer (Mac)

$100/yr Personal Developer Account

OSX 10.7+ for iOS 5.0+

iOS device to test on

Page 5: iOS Development - University of Cincinnati · 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,

Basics of iOS

Page 6: iOS Development - University of Cincinnati · 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,

C

C++

Languages

Page 7: iOS Development - University of Cincinnati · 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,

Objective - C

Languages

Page 8: iOS Development - University of Cincinnati · 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,

UI framework for iPhone, iPod, and iPad

Cocoa Touch

Page 9: iOS Development - University of Cincinnati · 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,

Core Animation

Multitasking

Gesture Recognition

Cocoa Touch

Page 10: iOS Development - University of Cincinnati · 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,

UIKit Objects

NS* Objects

Cocoa Touch

Page 11: iOS Development - University of Cincinnati · 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,

3D

Low level

C or C++

OpenGL ES

Page 12: iOS Development - University of Cincinnati · 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,

Best Practices

Page 13: iOS Development - University of Cincinnati · 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,

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.

Page 14: iOS Development - University of Cincinnati · 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,

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;

Page 15: iOS Development - University of Cincinnati · 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,

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

Page 16: iOS Development - University of Cincinnati · 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,

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

Page 17: iOS Development - University of Cincinnati · 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,

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 ":"

Page 18: iOS Development - University of Cincinnati · 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,

Classes

Interface

Definitions of:● Methods● Private variables● Public variables● Delegates

Implementation

Does all of the work

Page 19: iOS Development - University of Cincinnati · 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,

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

Page 20: iOS Development - University of Cincinnati · 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,

UIKit Hierarchy

Page 21: iOS Development - University of Cincinnati · 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,

Anatomy of a class

Page 22: iOS Development - University of Cincinnati · 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,

Interface

Page 23: iOS Development - University of Cincinnati · 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,

InterfaceClass

Page 24: iOS Development - University of Cincinnati · 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,

InterfaceClass

Private variables

Page 25: iOS Development - University of Cincinnati · 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,

InterfaceClass

Private variables

Public variables

Page 26: iOS Development - University of Cincinnati · 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,

InterfaceClass

Private variables

Public variables

Instance methods

Page 27: iOS Development - University of Cincinnati · 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,

InterfaceClass

Private variables

Public variables

Instance methods

Delegate

Page 28: iOS Development - University of Cincinnati · 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,

InterfaceClass

Private variables

Public variables

Instance methods

Delegate methods

Delegate

Page 29: iOS Development - University of Cincinnati · 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,

@propertyWhen an object is declared with @property, you must then use @synthesize in the implementation of your class.

Page 30: iOS Development - University of Cincinnati · 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,

@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

Page 31: iOS Development - University of Cincinnati · 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,

@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.

Page 32: iOS Development - University of Cincinnati · 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,

Implementation

Basic structure:

@synthesizeMethods

Deallocating

Page 33: iOS Development - University of Cincinnati · 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,

Delegates

Page 34: iOS Development - University of Cincinnati · 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,

Delegate Example@interface ImageLoader : NSObject

● Loads an image asynchronously● Sends a message �to its delegate when loaded● Declares method -(void)imageDidLoad

Page 35: iOS Development - University of Cincinnati · 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,

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

Page 36: iOS Development - University of Cincinnati · 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,

Delegate ExampleInside MyTableView.m

ImageLoader *imgLoader = [[ImageLoader alloc] init];imgLoader.delegate = self;

Page 37: iOS Development - University of Cincinnati · 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,

Delegate ExampleInside MyTableView.m

ImageLoader *imgLoader = [[ImageLoader alloc] init];imgLoader.delegate = self;

...

-(void)imageDidLoad{ ...}

Page 38: iOS Development - University of Cincinnati · 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,

Delegate Example

MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad

Page 39: iOS Development - University of Cincinnati · 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,

Delegate Example

MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad

BUT

ImageLoader sends message imageDidLoad to MyTableView

Page 40: iOS Development - University of Cincinnati · 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,

Delegate Example

MyTableView instantiates ImageLoaderImageLoader owns method -(void)imageDidLoad

BUT

ImageLoader sends message imageDidLoad to MyTableView

BUT

MyTableView defines what -(void)imageDidLoad does

Page 41: iOS Development - University of Cincinnati · 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,

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

Page 42: iOS Development - University of Cincinnati · 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,

Memory Management

Page 43: iOS Development - University of Cincinnati · 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,

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

Page 44: iOS Development - University of Cincinnati · 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,

PointersAll UI* and NS* objects are declared as pointers

Page 45: iOS Development - University of Cincinnati · 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,

PointersAll UI* and NS* objects are declared as pointers

NSArray *arr = [[NSArray alloc] init];

Page 46: iOS Development - University of Cincinnati · 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,

PointersAll UI* and NS* objects are declared as pointers

NSArray *arr = [[NSArray alloc] init];

Object

Page 47: iOS Development - University of Cincinnati · 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,

PointersAll UI* and NS* objects are declared as pointers

NSArray *arr = [[NSArray alloc] init];

Object AllocateMemory

Page 48: iOS Development - University of Cincinnati · 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,

PointersAll UI* and NS* objects are declared as pointers

NSArray *arr = [[NSArray alloc] init];

Object AllocateMemory

Initialization

Page 49: iOS Development - University of Cincinnati · 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,

PointersPointers have different states

retain, atomic, assign, copy, readonly, readwrite, strong

We should only really worry about retaining objects

Page 50: iOS Development - University of Cincinnati · 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,

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.

Page 51: iOS Development - University of Cincinnati · 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,

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.

Page 52: iOS Development - University of Cincinnati · 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,

PointersIn iOS 5.0+ Apple introduced Automatic Reference Counting (ARM) which is a simple garbage collector (memory manager).

ARM manages objects and releases them.

Page 53: iOS Development - University of Cincinnati · 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,

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!

Page 54: iOS Development - University of Cincinnati · 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,

FrameworksHundreds of Open Source and paid frameworks for games, boilerplates, extensions, etc.

Page 55: iOS Development - University of Cincinnati · 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,

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.

Page 56: iOS Development - University of Cincinnati · 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,

Contact

Ryan Nystrom

937.367.8939

[email protected]

Page 57: iOS Development - University of Cincinnati · 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,

More ResourcesProgramming iOS 5

O'Reilly Bookshttp://goo.gl/9LY6P

Apple's DocumentationXcode Docs

Page 58: iOS Development - University of Cincinnati · 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,

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