Upload
irving-ios-jumpstart
View
502
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Objective-C ProgrammingIrving iOS Jumpstart
Objective-C Programming
January 28, 2014 Part One
Overview of Today
• Objective-C History, Influence and Language Characteristics
• Object Orientated Programming (OOP)
• Sample Xcode project file layout
Overview of Today (cont.)
• Intro to Objective-C Language constructs
• data types
• variables
• operators
• flow control
• functions (from C language)
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
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
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.
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
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
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
Typed Variables• Structure
• data_type name = initial_value;
• examples
• int counter = 15;!
• float price = 10.95;!
• double exactnumber = 3.3456789
Typed Variables
• NSString *contactName;!
• UIViewController *contactsViewController;!
• NSArray *myContacts;
Exercise
• Hello World from (your name here)
Objective-C Operators
• + addition
• - subtraction
• * multiplication
• / division
Objective-C Operators (cont.)
• || logical OR
• && logical AND
• = assignment
• == comparison
Objective-C Flow Control
• if-else
• if ( temperature > 90 ) NSLog (@"It is too hot outside");
Objective-C Flow Control
• if-else
• if ( temperature > 90 ) NSLog (@"It is too hot outside");
• Compound Relational Tests
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.");
Objective-C Flow Control
• if-else
• Compound Relational Tests (cont.)
Objective-C Flow Control
• if-else
• Compound Relational Tests (cont.)
• if ( temperature < 90 && temperature > 65 ) NSLog (@"Weather conditions are perfect!");
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!");
}
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; }
Quick C Function Review
• for contrast with objective-c
C Functions• Function definition
return_value_type function_name (arguments)
• Example
void printMyName (void)
{
NSLog (@"My name is James");
}
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
Move On To Part Two
• Credits
• Wikipedia
• Apple Documentation
• Programming in Objective-C by Stephen Kochan
(any errors or omissions are probably my doing)