SlideShare a Scribd company logo
In This Deck 
MVC Architecture 
Objective-C Syntax 
Classes 
Instances 
Methods 
Properties 
Setters + Getters 
Header + Implementation 
Delegates + Protocols 
Xcode IDE 
Key Classes + Terms In Objective-C 
This deck is shared with you under a Creative Commons license.
Cloud Services User Input 
Model 
Coordinates between model and view 
Contains all application logic and data 
View 
Your application’s graphical user interface 
View Controller 
The MVC architecture is useful because it lets you abstract apart and organize your app into functional, 
replaceable modules. 
NSNotification 
MVC Architecture 
(Model + View + Controller)
MVC Architecture 
(Model + View + Controller) 
Model View Result 
+ = 
Tic Tac Toe Visual 
Tic Tac Toe Textual 
X played: (2, 3) 
O played: (3, 1) 
X played: (1, 3) 
SMS Textual 
Chris said: CoD? 
Adam said: nm, u? 
HJ said: sup 
same model • different view 
different model • same view
Objective-C 
Syntax 
[[Vehicle alloc] initWithMake:@“Toyota” model:@“Prius” color:[UIColor blackColor]]; 
Objective-C is a verbose language. 
Method names and variable names tend to be very long. 
This is supposed to make it easier to understand your code and how to use methods.
Objective-C 
Syntax 
Objective-C is an object-oriented language. 
Methods are really “messages” send to objects or classes telling them to do things. 
For example: 
[myCar setSpeed:50.0]; 
is really saying: 
“Tell myCar to set its speed to 50.0 mph.” 
50.0 mph, 
please!
Objective-C 
Syntax 
Xcode will attempt to autocomplete whatever you’re typing. 
This not only helps you save time (you can hit Tab to autocomplete) but also helps you discover relevant 
methods and properties.
Objective-C 
Classes 
Vehicle myCar yourCar 
> make @“Toyota” @“Lamborghini” 
> model @“Prius” @“Aventador” 
> speed 50.0 95.0 
Think of a class as a category, e.g., Vehicle. 
A class has no data but can perform some basic methods. 
A class also specifies what properties instances of that class should have. 
It’s kind of like a form that hasn’t been filled out. 
E.g., Vehicle might have properties for make, model, and speed.
Objective-C 
Classes 
Vehicle 
Car Truck Motorcycle 
All classes in Objective-C inherit some methods and properties from a superclass. 
As a result, each class is a subclass of another class. 
E.g., Vehicle might be a subclass of NSObject and might have its own subclasses Car, Truck, and 
Motorcycle that have all the properties and methods of Vehicles but also add their own properties and 
methods.
Objective-C 
Instances 
An instance is a specific instance of a class. 
E.g., myCar might be an instance of Car. 
An instance has data and may have some methods that you can perform on that data. 
E.g., For myCar, you would have the following values for your properties: 
myCar.make = @“Toyota”; 
myCar.model = @“Prius”; 
myCar.speed = 55.0; 
myCar.gas = 10.0; 
myCar.owner = @“Ken M. Haggerty”; 
Instances are often created using alloc and init, e.g.: 
[[Car alloc] init]; 
or using a “convenience” method, e.g.: 
[Car carWithOwner:@“Ken M. Haggerty”];
Objective-C 
Methods 
A class method is a method that is performed on a class rather than a specific instance of a class. 
Class methods are often useful for instantiation and general methods not specific to instances. 
E.g., [NSArray arrayWithObject:firstObject] creates a new array with one object in it, 
or, [TicTacToe howManyInARowToWin] might return 3. 
An instance method is a method that is performed on an instance of a class. 
Instance methods are useful for changing or manipulating instances of your class. 
E.g., If myString is set to @“filename”, 
[myString stringbyAppendingString:@“.png”] would return the string @“filename.png”.
Objective-C 
Properties 
Properties are how data are stored in instances of your class. 
They are like fields on a form. 
Each property defines what kind of data it should hold, but only instances of your class actually hold that 
data. 
E.g., Car might have the property 
@property (nonatomic) BOOL isNewCar; 
while myCar, an instance of Car, might have isNewCar set to NO.
Objective-C 
Setters + Getters 
When you create a property, Objective-C will automatically create helper methods for accessing and setting 
values for your property. 
I.e., When you create: 
@property (nonatomic, strong) NSString *owner; 
Objective-C will create the following two instance methods for you: 
- (void)setOwner:(NSString *)owner; 
- (NSString *)owner; 
Both of these methods are accessible to you as soon as you define your property. 
However, you can always write your own custom implementation for your helper and/or getter.
Objective-C 
Setters + Getters 
Setters are only called when that property is being set explicitly, e.g.: 
[myCar setOwner:@“Ken M. Haggerty”]; 
myCar.owner = @“Ken M. Haggerty”; 
Getters can be called in either of the following ways: 
[usa name]; 
usa.name; 
The second syntax in each of the above examples is called dot notation and is usually only used for 
properties in Objective-C.
Objective-C 
Header + Implementation Files 
“Burger, please!” 
(returns burger) 
<YourClass>.h 
Dictates public interface for this class; i.e., how other 
classes can and should interact with this class. 
● Imports (#import) 
● Protocols (@protocol) 
● Public API (@interface) 
<YourClass>.m 
Dictates private interface for this class + contains all 
method implementations for this class. 
● Imports (#import) 
● Private API (@interface) 
● Implementation (@implementation) 
In Objective-C, the header (.h) file is “public” while the implementation file (.m) is “private.” 
The header file should be organized, clear, and state what the class does and how to use it.
Objective-C 
Delegates + Protocols 
In well-written Objective-C, your model and your view are completely agnostic of each other. 
I.e., Your model should not be in any way dependent on how it is ultimately presented to the user, and your 
view should not care what kind of data it is representing. 
Instead, your model and view should communicate using the following relationships: 
● Your view controller can change your model. 
● Your model can change itself. 
● Your model can send out notifications when it is changed. 
● Your view controller can listen for notifications and act accordingly. 
● Your view controller can change your view. 
To do this, we often used delegates to delegate methods and properties from view controllers to models. 
E.g., UITableViewController has two delegates: delegate and dataSource. 
When assigning delegates, we can ensure that our delegates implement the necessary properties and 
methods by specifying protocols that they should follow. 
We can dictate what protocols a property should follow when defining them. E.g.: 
@property (nonatomic, weak) id <MyProtocol> delegate;
Xcode IDE 
(Integrated Development Environment) 
Demo 
There’s a lot going on in Xcode, so we’ll explore by clicking around. 
If you have trouble using Xcode or have any questions, don’t hesitate! Ken will be happy to help.
Objective-C 
Key Classes + Terms 
NSObject or id: Top-level object in Objective-C. Almost all objects in Objective-C inherit 
from NSObject. 
UIViewController: A basic view controller in Objective-C. All view controllers inherit from 
UIViewController. 
UIView: A basic view in Objective-C. Views are always rectangles. All views inherit from 
UIView. Views can be placed as subviews within another view. 
UIButton: A basic button in Objective-C. Buttons can respond to touch events. 
UIImage: An image in Objective-C. 
UIImageView: A subclass of UIView designed for displaying an image. 
UIScrollView: A subclass of UIView designed for scrolling content. Scrollviews are tricky 
but incredibly useful. 
IBOutlet / IBAction: Designates that a property / method should be connected to a view 
via Interface Builder. 
nonatomic / atomic: You will always use nonatomic. This has to do with thread safety 
regarding setters and getters for properties. 
strong / weak: Determines whether a property’s value should be held even if no other 
object is pointing to that value. Strong = yes, weak = no. 
self: Used within an instance method to refer to the instance the method was sent to. 
Interface Builder / Storyboard: Visual interface within Xcode IDE for laying out and 
creating your app’s GUI. 
UITableViewController: A subclass of UIScrollView designed for presenting scrollable 
tables. 
UITableView: A subclass of UIScrollView designed for presenting scrollable tables. 
UITableViewCell: A subclass of UIView designed for presenting content in tables. 
UITableViewCells are reused as the table view is scrolled, increasing responsivity and 
smoothness. 
NSArray: A subclass of NSObject that contains an uneditable list of NSObjects. 
NSMutableArray: A subclass of NSArray where its list of NSObjects are editable. 
NSString: A subclass of NSObject for text. 
BOOL: A binary type that’s actually just plain C. Can have value YES or NO. 
int: A C class for storing integer values. 
float: A C class for storing floats (i.s., decimal values). 
#import: Add a library, framework, or another class to the current class. 
Apple has very thorough documentation available from within Xcode at Help > Documentation and API Reference 
and online at https://developer.apple.com/library/ios/navigation/

More Related Content

What's hot

Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
lykado0dles
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
Haresh Jaiswal
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11
Niit Care
 

What's hot (20)

Classes2
Classes2Classes2
Classes2
 
Java beans
Java beansJava beans
Java beans
 
C++ to java
C++ to javaC++ to java
C++ to java
 
constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programming
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Objective c
Objective cObjective c
Objective c
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructor
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11
 
Constructor
ConstructorConstructor
Constructor
 
Methods and constructors in java
Methods and constructors in javaMethods and constructors in java
Methods and constructors in java
 

Similar to Intro to iOS Development • Made by Many

Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
Milind Patil
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 

Similar to Intro to iOS Development • Made by Many (20)

Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Angular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advancedAngular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advanced
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Object Oriented Programming (Advanced )
Object Oriented Programming   (Advanced )Object Oriented Programming   (Advanced )
Object Oriented Programming (Advanced )
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Cble assignment powerpoint activity for moodle 1
Cble assignment powerpoint activity for moodle 1Cble assignment powerpoint activity for moodle 1
Cble assignment powerpoint activity for moodle 1
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+Reflection
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
 
OOP and C++Classes
OOP and C++ClassesOOP and C++Classes
OOP and C++Classes
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 

Intro to iOS Development • Made by Many

  • 1.
  • 2. In This Deck MVC Architecture Objective-C Syntax Classes Instances Methods Properties Setters + Getters Header + Implementation Delegates + Protocols Xcode IDE Key Classes + Terms In Objective-C This deck is shared with you under a Creative Commons license.
  • 3. Cloud Services User Input Model Coordinates between model and view Contains all application logic and data View Your application’s graphical user interface View Controller The MVC architecture is useful because it lets you abstract apart and organize your app into functional, replaceable modules. NSNotification MVC Architecture (Model + View + Controller)
  • 4. MVC Architecture (Model + View + Controller) Model View Result + = Tic Tac Toe Visual Tic Tac Toe Textual X played: (2, 3) O played: (3, 1) X played: (1, 3) SMS Textual Chris said: CoD? Adam said: nm, u? HJ said: sup same model • different view different model • same view
  • 5. Objective-C Syntax [[Vehicle alloc] initWithMake:@“Toyota” model:@“Prius” color:[UIColor blackColor]]; Objective-C is a verbose language. Method names and variable names tend to be very long. This is supposed to make it easier to understand your code and how to use methods.
  • 6. Objective-C Syntax Objective-C is an object-oriented language. Methods are really “messages” send to objects or classes telling them to do things. For example: [myCar setSpeed:50.0]; is really saying: “Tell myCar to set its speed to 50.0 mph.” 50.0 mph, please!
  • 7. Objective-C Syntax Xcode will attempt to autocomplete whatever you’re typing. This not only helps you save time (you can hit Tab to autocomplete) but also helps you discover relevant methods and properties.
  • 8. Objective-C Classes Vehicle myCar yourCar > make @“Toyota” @“Lamborghini” > model @“Prius” @“Aventador” > speed 50.0 95.0 Think of a class as a category, e.g., Vehicle. A class has no data but can perform some basic methods. A class also specifies what properties instances of that class should have. It’s kind of like a form that hasn’t been filled out. E.g., Vehicle might have properties for make, model, and speed.
  • 9. Objective-C Classes Vehicle Car Truck Motorcycle All classes in Objective-C inherit some methods and properties from a superclass. As a result, each class is a subclass of another class. E.g., Vehicle might be a subclass of NSObject and might have its own subclasses Car, Truck, and Motorcycle that have all the properties and methods of Vehicles but also add their own properties and methods.
  • 10. Objective-C Instances An instance is a specific instance of a class. E.g., myCar might be an instance of Car. An instance has data and may have some methods that you can perform on that data. E.g., For myCar, you would have the following values for your properties: myCar.make = @“Toyota”; myCar.model = @“Prius”; myCar.speed = 55.0; myCar.gas = 10.0; myCar.owner = @“Ken M. Haggerty”; Instances are often created using alloc and init, e.g.: [[Car alloc] init]; or using a “convenience” method, e.g.: [Car carWithOwner:@“Ken M. Haggerty”];
  • 11. Objective-C Methods A class method is a method that is performed on a class rather than a specific instance of a class. Class methods are often useful for instantiation and general methods not specific to instances. E.g., [NSArray arrayWithObject:firstObject] creates a new array with one object in it, or, [TicTacToe howManyInARowToWin] might return 3. An instance method is a method that is performed on an instance of a class. Instance methods are useful for changing or manipulating instances of your class. E.g., If myString is set to @“filename”, [myString stringbyAppendingString:@“.png”] would return the string @“filename.png”.
  • 12. Objective-C Properties Properties are how data are stored in instances of your class. They are like fields on a form. Each property defines what kind of data it should hold, but only instances of your class actually hold that data. E.g., Car might have the property @property (nonatomic) BOOL isNewCar; while myCar, an instance of Car, might have isNewCar set to NO.
  • 13. Objective-C Setters + Getters When you create a property, Objective-C will automatically create helper methods for accessing and setting values for your property. I.e., When you create: @property (nonatomic, strong) NSString *owner; Objective-C will create the following two instance methods for you: - (void)setOwner:(NSString *)owner; - (NSString *)owner; Both of these methods are accessible to you as soon as you define your property. However, you can always write your own custom implementation for your helper and/or getter.
  • 14. Objective-C Setters + Getters Setters are only called when that property is being set explicitly, e.g.: [myCar setOwner:@“Ken M. Haggerty”]; myCar.owner = @“Ken M. Haggerty”; Getters can be called in either of the following ways: [usa name]; usa.name; The second syntax in each of the above examples is called dot notation and is usually only used for properties in Objective-C.
  • 15. Objective-C Header + Implementation Files “Burger, please!” (returns burger) <YourClass>.h Dictates public interface for this class; i.e., how other classes can and should interact with this class. ● Imports (#import) ● Protocols (@protocol) ● Public API (@interface) <YourClass>.m Dictates private interface for this class + contains all method implementations for this class. ● Imports (#import) ● Private API (@interface) ● Implementation (@implementation) In Objective-C, the header (.h) file is “public” while the implementation file (.m) is “private.” The header file should be organized, clear, and state what the class does and how to use it.
  • 16. Objective-C Delegates + Protocols In well-written Objective-C, your model and your view are completely agnostic of each other. I.e., Your model should not be in any way dependent on how it is ultimately presented to the user, and your view should not care what kind of data it is representing. Instead, your model and view should communicate using the following relationships: ● Your view controller can change your model. ● Your model can change itself. ● Your model can send out notifications when it is changed. ● Your view controller can listen for notifications and act accordingly. ● Your view controller can change your view. To do this, we often used delegates to delegate methods and properties from view controllers to models. E.g., UITableViewController has two delegates: delegate and dataSource. When assigning delegates, we can ensure that our delegates implement the necessary properties and methods by specifying protocols that they should follow. We can dictate what protocols a property should follow when defining them. E.g.: @property (nonatomic, weak) id <MyProtocol> delegate;
  • 17. Xcode IDE (Integrated Development Environment) Demo There’s a lot going on in Xcode, so we’ll explore by clicking around. If you have trouble using Xcode or have any questions, don’t hesitate! Ken will be happy to help.
  • 18. Objective-C Key Classes + Terms NSObject or id: Top-level object in Objective-C. Almost all objects in Objective-C inherit from NSObject. UIViewController: A basic view controller in Objective-C. All view controllers inherit from UIViewController. UIView: A basic view in Objective-C. Views are always rectangles. All views inherit from UIView. Views can be placed as subviews within another view. UIButton: A basic button in Objective-C. Buttons can respond to touch events. UIImage: An image in Objective-C. UIImageView: A subclass of UIView designed for displaying an image. UIScrollView: A subclass of UIView designed for scrolling content. Scrollviews are tricky but incredibly useful. IBOutlet / IBAction: Designates that a property / method should be connected to a view via Interface Builder. nonatomic / atomic: You will always use nonatomic. This has to do with thread safety regarding setters and getters for properties. strong / weak: Determines whether a property’s value should be held even if no other object is pointing to that value. Strong = yes, weak = no. self: Used within an instance method to refer to the instance the method was sent to. Interface Builder / Storyboard: Visual interface within Xcode IDE for laying out and creating your app’s GUI. UITableViewController: A subclass of UIScrollView designed for presenting scrollable tables. UITableView: A subclass of UIScrollView designed for presenting scrollable tables. UITableViewCell: A subclass of UIView designed for presenting content in tables. UITableViewCells are reused as the table view is scrolled, increasing responsivity and smoothness. NSArray: A subclass of NSObject that contains an uneditable list of NSObjects. NSMutableArray: A subclass of NSArray where its list of NSObjects are editable. NSString: A subclass of NSObject for text. BOOL: A binary type that’s actually just plain C. Can have value YES or NO. int: A C class for storing integer values. float: A C class for storing floats (i.s., decimal values). #import: Add a library, framework, or another class to the current class. Apple has very thorough documentation available from within Xcode at Help > Documentation and API Reference and online at https://developer.apple.com/library/ios/navigation/