26
Objective-C Programming Irving iOS Jumpstart

Irving iOS Jumpstart Meetup - Objective-C Session 1a

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C ProgrammingIrving iOS Jumpstart

Page 2: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Programming

January 28, 2014 Part One

Page 3: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Overview of Today

• Objective-C History, Influence and Language Characteristics

• Object Orientated Programming (OOP)

• Sample Xcode project file layout

Page 4: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Overview of Today (cont.)

• Intro to Objective-C Language constructs

• data types

• variables

• operators

• flow control

• functions (from C language)

Page 5: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C

Objective-C is a general-purpose, high-level, object oriented programming language that adds Smalltalk-

style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems and their respective

APIs, Cocoa and Cocoa Touch.

Wikipedia

Page 6: Irving iOS Jumpstart Meetup - Objective-C Session 1a

History and Influence

• Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s

• Original design influenced by Smalltalk

• An evolutionary approach to object oriented programming

Page 7: Irving iOS Jumpstart Meetup - Objective-C Session 1a

NeXT• Steve Jobs licensed objective-c (then

OpenStep) for use in NeXT computers

• Built the foundations of what would go on to become Cocoa and Cocoa touch APIs in OS X

• Most of Apple's present-day Cocoa API is based on OpenStep interface objects, and is the most significant Objective-C environment being used for active development.

Page 8: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Language Characteristics

• strict superset of C

• essentially C code with object syntax derived from Smalltalk

• syntax for non-object-oriented operations (including primitive variables, pre-processing, expressions, function declarations, and function calls) are identical to that of C

Page 9: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Data Types• C Basic Data Types

• int - integer value

• float - floating point value to 6 digits precision

• double - larger than float, to 10 digits precision

• char - single character value

• _Bool - contains a 0 or 1 and is useful for True/False operations

Page 10: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Variables and Scope

• A variable is the human readable 'container' in which a value is manipulated and/or stored.

• Scope is the context in which the variable is 'visible' or otherwise accessible for access and manipulation by the program code

Page 11: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Typed Variables• Structure

• data_type name = initial_value;

• examples

• int counter = 15;!

• float price = 10.95;!

• double exactnumber = 3.3456789

Page 12: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Typed Variables

• NSString *contactName;!

• UIViewController *contactsViewController;!

• NSArray *myContacts;

Page 13: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Exercise

• Hello World from (your name here)

Page 14: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Operators

• + addition

• - subtraction

• * multiplication

• / division

Page 15: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Operators (cont.)

• || logical OR

• && logical AND

• = assignment

• == comparison

Page 16: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

• if ( temperature > 90 ) NSLog (@"It is too hot outside");

Page 17: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

• if ( temperature > 90 ) NSLog (@"It is too hot outside");

• Compound Relational Tests

Page 18: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

• if ( temperature > 90 ) NSLog (@"It is too hot outside");

• Compound Relational Tests

• if ( temperature > 90 || temperature < 55 ) NSLog (@"Weather conditions are not best.");

Page 19: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

• Compound Relational Tests (cont.)

Page 20: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

• Compound Relational Tests (cont.)

• if ( temperature < 90 && temperature > 65 ) NSLog (@"Weather conditions are perfect!");

Page 21: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

• if-else

if ( temperature < 90 ) {

NSLog (@"It may be cool enough to play"

} else {

NSLog (@"It's too hot to play!");

}

Page 22: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Objective-C Flow Control

switch ( temperature) {

case 75: NSLog (@"The weather is just right!"); break; case 85: NSLog (@"It's a good time to swim"); break; default: NSLog (@"I don't know whether we will play outside"); break; }

Page 23: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Quick C Function Review

• for contrast with objective-c

Page 24: Irving iOS Jumpstart Meetup - Objective-C Session 1a

C Functions• Function definition

return_value_type function_name (arguments)

• Example

void printMyName (void)

{

NSLog (@"My name is James");

}

Page 25: Irving iOS Jumpstart Meetup - Objective-C Session 1a

C Functions• Function definition

return_value_type function_name (arguments)

• Example two

void printTheTemperature (int temp)

{

NSLog (@"The temperature is %i", temp);

}

//notice format specifier %i

Page 26: Irving iOS Jumpstart Meetup - Objective-C Session 1a

Move On To Part Two

• Credits

• Wikipedia

• Apple Documentation

• Programming in Objective-C by Stephen Kochan

(any errors or omissions are probably my doing)