SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
Objective-C Programming
Irving iOS Jumpstart
Objective-C
Programming
March 11, 2014
Overview of Today
• Quick 5 Realms Overview
• Objective-C Messaging
• Simple Programmatic UITableView Example
• Realistic UITableView Example
5 Realms
for Learning iOS Development
Download full 5 Realms presentation at:
http://www.slideshare.net/irving-ios-jumpstart/5-realms
Why 5 Realms?
To the beginning iOS developer the formalities of
classes, frameworks, design patterns, and
learning an all new integrated development
environment can be overwhelming.
Why 5 Realms?
Knowing which realm you're having trouble in really
helps in finding the solution and getting unstuck in
your learning efforts.
5 Realms
Design
Patterns
Objective-C
iOS SDK OOP
Xcode
IDE
Objective-C
Messaging
Objective-C
Defining Classes in
Objective-C
• Created via .h file and .m file
• All classes inherit from NSObject or another
class
Objective-C
@interface
@implementation
• @interface in an objective-c .h file
• @implementation in an objective-c .m file
• serves to separate the interface of a class
from its implementation.
Objective-C
@property
@synthesize
• Objective-C properties
• @property directive is used to create
properties on the class.
• Properties are accessed (read and set) via
automagically created setters and getters.
• In Xcode 5, optionally use @synthesize to
give instance variable a custom name
Objective-C
Objective-C Methods
• Class method
+ (return_type)methodName
• Instance method
- (return_type)methodName
• Distinguished by + or -
Objective-C
Objective-C Methods
- (void)addHotels
{
NSArray *hotels = [NSArray
arrayWithObjects:@"Aloft", @"The
W", @"Hilton", nil];
ourHotels = [NSArray
arrayWithArray:hotels];
}
- (return_type)methodName
Objective-C
Method With
Arguments
• this method has one argument
- (void)listOurHotelsUsingTitle:
(NSString *)title
{
NSLog(@"%@: %@", title,
ourHotels);
}
Objective-C
Method With
Arguments
• including sample method call below
- (void)listOurHotelsUsingTitle:(NSString *)title
{
NSLog(@"%@: %@", title, ourHotels);
}
!
[self listOurHotelsUsingTitle:@"Favorite Hotels"];
Objective-C
Foundation
Framework
• NSString - the Foundation Framework
class used to create string objects!
NSString *city = @"Irving";
iOS SDK
Foundation
Framework
NSString *myStory = [NSString
stringWithFormat:@"The brown fox
lives in %@", city];
//The brown fox lives in Irving
iOS SDK
Foundation
Framework
• NSString comparison
if ([city isEqualToString:@"Irving"]) {
NSLog(@"The two strings are the
same.");
} else {
NSLog(@"The two strings are
different.");
} //The two strings are the same.
iOS SDK
Foundation
Framework
• NSString comparison
if ([city isEqualToString:myStory]) {
NSLog(@"The two strings are the
same.");
} else {
NSLog(@"The two strings are
different.");
} //The two strings are different.
iOS SDK
Foundation
Framework
• NSArray - the Foundation Framework class
used to create array objects!
NSArray *hotels = [NSArray
arrayWithObjects:@"Aloft", @"The
W", @"Hilton", nil];
• An array is a set of ordered data items
iOS SDK
Foundation
Framework
NSArray *hotels = [NSArray
arrayWithObjects:@"Aloft", @"The
W", @"Hilton", nil];
• array index begins at zero, so an array with
3 elements are indexed 0, 1, and 2
NSLog(@"The hotel at index 1 in
this array is %@", [hotels
objectAtIndex:1]); // The W
iOS SDK
Foundation
Framework
• NSArray shortcut (objective-c literals)!
NSArray *hotels = @[@"Aloft",
@"The W", @"Hilton"];
• Cleaner and familiar syntax
iOS SDK
Foundation
Framework
• NSDictionary - the Foundation Framework
class used to store key and value pairs!
NSDictionary *hotels =
[NSDictionary
dictionaryWithObjectsAndKeys:@"5
star", @"Aloft", @"4 star", @"W",
@"5 star", @"Hilton", nil];
iOS SDK
Foundation
Framework
- (void)addHotelsWithRatings
{
NSDictionary *hotels = [NSDictionary
dictionaryWithObjectsAndKeys:@"5 star",
@"Aloft", @"4 star", @"W", @"5 star",
@"Hilton", nil];
!
NSLog(@"%@", hotels);
}
iOS SDK
Foundation
Framework
• NSDictionary shortcut (objective-c literals)!
NSDictionary *hotels =
@{@"Aloft":@"5 star", @"W":@"4
star", @"Hilton":@"5 star"};
• Cleaner syntax
iOS SDK
Foundation
Framework
• Mutable objects are changeable after
creation.
• Immutable objects cannot change once they
are created.
• Therefore additional methods exist on mutable
objects
iOS SDK
Mutable Objects
NSString (immutable)
NSMutableString (mutable)
NSArray
NSMutableArray
NSDictionary
NSMutableDictionary
iOS SDK
Mutable Objects
• NSMutableString Example
NSMutableString *iCanChange =
[NSMutableString
stringWithString:@"Hello..."];
NSLog(@"%@", [iCanChange
stringByAppendingString:@"world!"]);
// Hello...world!
iOS SDK
Mutable Objects
Download samples from github
!
https://github.com/jamesderry
iOS SDK
Programmatic
UITableView
Crosses several realms of IOS understanding.
!
!
!
Design
Patterns
Objective-C
iOS SDK OOP
Xcode
IDE
Programmatic
UITableView
• Xcode
• Storyboard - we'll build the view controller
storyboard containing a tableview
• IBOutlet - we'll use to grab a handle to the
tableview for manipulation in objective-c
code
Xcode
IDE
Programmatic
UITableView
• Design Patterns
• Model - View - Controller (MVC) pattern
• Delegate pattern
• Datasource pattern
Design
Patterns
Programmatic
UITableView
• Objective-C features
• Protocols
• Classes (UITableView and UITableViewCell)
• Dot syntax for cell properties
Objective-C
Programmatic
UITableView
• iOS SDK Features
• UIViewController (and view controller life
cycle)
• UIView
• UITableView and UITableViewCell
iOS SDK
Programmatic
UITableView Exercise
Create simple table view app
Programmatic
UITableView Exercise
Common Pitfalls
• forgetting to match the prototype cell identifier
name to the name used in your code
• forgetting to set the tableview datasource and
delegate
Thank You!
• Credits
• Wikipedia
• Programming in Objective-C by Stephen
Kochan
(any errors or omissions are probably mine)

Weitere ähnliche Inhalte

Ähnlich wie Irving iOS Jumpstart Meetup - Objective-C Session 2

Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
Petr Dvorak
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful Backend
Stefano Zanetti
 

Ähnlich wie Irving iOS Jumpstart Meetup - Objective-C Session 2 (20)

iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
iOS & Drupal
iOS & DrupaliOS & Drupal
iOS & Drupal
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talk
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
 
Streamlining JSON mapping
Streamlining JSON mappingStreamlining JSON mapping
Streamlining JSON mapping
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful Backend
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
Bring your code to explore the Azure Data Lake: Execute your .NET/Python/R co...
Bring your code to explore the Azure Data Lake: Execute your .NET/Python/R co...Bring your code to explore the Azure Data Lake: Execute your .NET/Python/R co...
Bring your code to explore the Azure Data Lake: Execute your .NET/Python/R co...
 
Cappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkCappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application Framework
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Irving iOS Jumpstart Meetup - Objective-C Session 2