SlideShare a Scribd company logo
1 of 35
1 
Introduction to Objective-C 
and 
iPhone Development
2 
Introduction 
• Objective-C is implemented as set of extensions 
to the C language. 
• It's designed to give C a full capability for object-oriented 
programming, and to do so in a simple 
and straightforward way. 
• Its additions to C are few and are mostly based 
on Smalltalk, one of the first object-oriented 
programming languages.
3 
Why Objective C 
• Objective-C incorporates C, you get all the benefits of C 
when working within Objective-C. 
• You can choose when to do something in an object-oriented 
way (define a new class, for example) and when 
to stick to procedural programming techniques (define a 
struct and some functions instead of a class). 
• Objective-C is a simple language. Its syntax is small, 
unambiguous, and easy to learn 
• Objective-C is the most dynamic of the object-oriented 
languages based on C. Most decisions are made at run 
time.
4 
Object-Oriented Programming 
• The insight of object-oriented programming is to 
combine state and behavior, data and 
operations on data, in a high-level unit, an 
object, and to give it language support. 
• An object is a group of related functions and a 
data structure that serves those functions. The 
functions are known as the object's methods, 
and the fields of its data structure are its 
instance variables.
5 
The Objective-C Language 
• The Objective-C language is fully 
compatible with ANSI standard C 
• Objective-C can also be used as an 
extension to C++. 
• Although C++ itself is a Object-Oriented 
Language, there are difference in the 
dynamic binding from Objective-C
6 
Objective-C Language (cont.) 
• Objective-C source files have a “.m” 
extension 
• “.h” file is the interface file 
• For example: 
– main.m 
– List.h (Interface of List class.) 
– List.m (Implementation of List class.)
7 
ID 
• “id” is a data type used by Objective-C to 
define a pointer of an object (a pointer to 
the object’s data) 
• Any type of object, as long as it is an 
object, we can use the id data type. 
• For example, we can define an object by: 
id anObject; 
• nil is the reserved word for null object
8 
Dynamic Typing 
• “id” data type has no information about the 
object 
• Every object carries with it an isa instance 
variable that identifies the object's class, 
that is, what kind of object it is. 
• Objects are thus dynamically typed at run 
time. Whenever it needs to, the run-time 
system can find the exact class that an 
object belongs to, just by asking the object
9 
Messages 
• To get an object to do something, you 
send it a message telling it to apply a 
method. In Objective-C, message 
expressions are enclosed in square 
brackets 
[receiver message] 
• The receiver is an object. The message is 
simply the name of a method and any 
arguments that are passed to it
10 
Messages (cont.) 
• For example, this message tells the myRect 
object to perform its display method, which 
causes the rectangle to display itself 
[myRect display]; 
[myRect setOrigin:30.0 :50.0]; 
• The method setOrigin::, has two colons, one for 
each of its arguments. The arguments are 
inserted after the colons, breaking the name 
apart
11 
Polymorphism 
• Each object has define its own method but for 
different class, they can have the same method 
name which has totally different meaning 
• The two different object can respond differently 
to the same message 
• Together with dynamic binding, it permits you to 
write code that might apply to any number of 
different kinds of objects, without having to 
choose at the time you write the code what kinds 
of objects they might be
12 
Inheritance 
• Root class is NSObject 
• Inheritance is cumulative. 
A Square object has the 
methods and instance 
variables defined for 
Rectangle, Shape, 
Graphic, and NSObject, 
as well as those defined 
specifically for Square
13 
Inheritance (cont.) 
• Instance Variables: The new object contains not only the 
instance variables that were defined for its class, but 
also the instance variables defined for its super class, all 
the way back to the root class 
• Methods: An object has access not only to the methods 
that were defined for its class, but also to methods 
defined for its super class 
• Method Overriding: Implement a new method with the 
same name as one defined in a class farther up the 
hierarchy. The new method overrides the original; 
instances of the new class will perform it rather than the 
original
Primitive data types from C 
• int, short, long 
• float,double 
• char 
14
Operators same as C 
• + 
• - 
• * 
• / 
• ++ 
• -- 
15
Address and Pointers 
• Same as C 
• To get address of a variable i 
&i 
• Pointer 
int *addressofi = &I; 
16
Conditionals and Loops 
• Same as C/C++ 
• if / else if/ else 
• for 
• while 
• break 
• ontinue 
• do-while 
for(int i=0; i< 22; i++) { 
NSLog(“Checking i =“%d”, i); 
if(i == 12) 
{ break;} 
} 
17
18 
for in loop 
• Introduced in Objective-C 2.0 (“fast enumeration”) 
for(Item_Type *item in Collection_of_Items) { 
//do whatever with the item 
Nslog(@” Looking now at %@”, item); 
}
19 
Functions 
• Same as C/C++ 
• return_type functionName(type v1, type v2, ….) 
{ //code of function 
} 
Example 
void showMeInfo(int age) 
{ 
printf(“You are %d years old”, age); //or use NSLog() 
}
20 
Global and static variables 
• Same as C/C++ 
• Global variables defined at top of file 
• For static variables use keyword static before it 
static in CurrentYear = 2013;
Automatic Reference Counting 
21 
• Objective C uses ‘AUTOMATIC reference 
counting' as memory management 
• keeps an internal count of how many times 
an Object is 'needed'. 
• System makes sure that objects that are 
needed are not deleted, and when an 
object is not needed it is deleted.
22 
Defining a Class 
• In Objective-C, classes are defined in two 
parts: 
– An interface that declares the methods and 
instance variables of the class and names its 
super class 
– An implementation that actually defines the 
class (contains the code that implements its 
methods)
23 
The Interface 
• The declaration of a class interface begins 
with the compiler directive @interface and 
ends with the directive @end 
@interface ClassName : ItsSuperclass 
{ 
instance variable declarations 
} 
method declarations 
@end
24 
Declaration 
• Instance Variables 
float width; 
float height; 
BOOL filled; 
NSColor *fillColor; 
• Methods: 
• names of methods that can be used by class objects, 
class methods, are preceded by a plus sign 
+ alloc 
• methods that instances of a class can use, instance 
methods, are marked with a minus sign: 
- (void) display;
25 
Declaration (cont.) 
• Importing the Interface: The interface is 
usually included with the #import directive 
#import "Rectangle.h" 
• To reflect the fact that a class definition builds on 
the definitions of inherited classes, an interface 
file begins by importing the interface for its super 
class 
• Referring to Other Classes: If the interface 
mentions classes not in this hierarchy, it must 
declare them with the @class directive: 
@class Rectangle, Circle;
26 
Creating class instances 
ClassName *object = [[ClassName alloc] init]; 
ClassName *object = [[ClassName alloc] initWith* ]; 
– NSString* myString = [[NSString alloc] init]; 
– Nested method call. The first is the alloc method called on NSString itself. 
This is a relatively low-level call which reserves memory and instantiates 
an object. The second is a call to init on the new object. The init 
implementation usually does basic setup, such as creating instance 
variables. The details of that are unknown to you as a client of the class. 
In some cases, you may use a different version of init which takes input: 
ClassName *object = [ClassName method_to_create]; 
– NSString* myString = [NSString string]; 
– Some classes may define a special method that will in essence call alloc followed by 
some kind of init
27 
Example: Hello World 
#import <Foundation/Foundation.h> 
int main (int argc, const char * argv[]) { 
NSAutoreleasePool * pool = 
[[NSAutoreleasePool alloc] init]; 
// insert code here... 
NSLog(@"Hello, World!"); 
[pool drain]; 
return 0; 
} 
NSLog() is equivalent to a C printf() 
Very similar to C 
C programs are valid in Objective-C
28 
Intro to HelloWorld 
• Objective-C uses a string class similar to the 
std::string or Java string. It is called NSString. 
• Constant NSStrings are preceded by @ for 
example: @”Hello World” 
• You will notice that NSLog() also outputs time 
and date and various extra information. 
• NSAutoreleasePool* pool =[[NSAutoreleasePool 
• alloc] init]; allocates a lump of memory 
• Memory must be freed with [pool drain];
29 
Some things to note 
• No line break needed at end of NSLog 
statements. 
• NSString constants use C-style variables. 
• Test this program to see results.
30 
@interface 
@interface ClassName : ParentClassName 
{ 
declare member variable here; 
declare another member variable here; 
} 
declare method functions here; 
@end 
• Equivalent to C class declaration 
• Goes in header (.h) file 
• Functions outside curly braces 
• Don’t forget the @end tag
31 
@implementation 
#import <Foundation/Foundation.h> 
#include "ComputerScience.h“ 
@implementation ClassName 
define method function here; 
define another method function here; 
define yet another method function here; 
@end 
● Equivalent to C class function definitions 
● Goes in source (.m) file 
● Don't forget the @end tag
32 
Some things to note 
• NSObject is the “root” object in Objective-C 
• No direct access to instance variables so we write 
some get/set “instance methods” 
• Instance methods (affect internal state of class) 
are preceded with a minus sign 
• “Class methods” (higher level functions) are 
preceded with a plus sign e.g. create new class 
• Method return type in parentheses 
• Semicolon before list of parameters 
• Parameter type in parenthesis, followed by name
33 
Data Structures 
• Objective-C arrays are similar to C arrays, but 
you can initialize whole array in a list. 
• Or just a few indices of the array. The rest are 
set to 0. 
• Or mix and match; the example will create an 
array of size [8]. 
int values[3] = { 3, 4, 2 }; 
char letters[3] = { 'a', 'c', 'x' }; 
float grades[100] = {10.0,11.2,1.1}; 
int array[] = {[3]=11,[2]=1,[7]=0};
34 
Multi-dimensional Arrays 
• Can be initialized by using subset notation with 
braces. Note no comma after second subset. 
• Subset braces are optional, the compiler will fill 
in blanks where it can as with 1D arrays. 
int array[2][3] = { 
{ 0, 3, 4}, 
{ 1, 1, 1} 
}; 
int array[2][3] = {0, 3, 4, 1, 1, 1};
35 
Frameworks 
• UIKit.framework for developing standard iOS GUIs 
(buttons etc.) 
• UITextField (user-entered text that brings up the 
keyboard) 
• UIFont 
• UIView 
• UITableView 
• UIImageView 
• UIImage 
• UIButton (a click-able button) 
• UILabel (a string of text on-screen) 
• UIWindow (main Window on iPhone)

More Related Content

What's hot

constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++HalaiHansaika
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstractionHoang Nguyen
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in pythontuan vo
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 
Ios development
Ios developmentIos development
Ios developmentelnaqah
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsVineeta Garg
 

What's hot (19)

Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C++ oop
C++ oopC++ oop
C++ oop
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Basic c#
Basic c#Basic c#
Basic c#
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 
Ios development
Ios developmentIos development
Ios development
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 

Viewers also liked

Programming in Objective-C
Programming in Objective-CProgramming in Objective-C
Programming in Objective-CRyan Chung
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework Eakapong Kattiya
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcodeSunny Shaikh
 
Gpu with cuda architecture
Gpu with cuda architectureGpu with cuda architecture
Gpu with cuda architectureDhaval Kaneria
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective cKenny Nguyen
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS IntroductionPratik Vyas
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 

Viewers also liked (16)

Programming in Objective-C
Programming in Objective-CProgramming in Objective-C
Programming in Objective-C
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Advanced iOS
Advanced iOSAdvanced iOS
Advanced iOS
 
Swine flu
Swine flu Swine flu
Swine flu
 
Objective-C @ ITIS
Objective-C @ ITISObjective-C @ ITIS
Objective-C @ ITIS
 
HDMI
HDMIHDMI
HDMI
 
Gpu with cuda architecture
Gpu with cuda architectureGpu with cuda architecture
Gpu with cuda architecture
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective c
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS Introduction
 
Ios operating system
Ios operating systemIos operating system
Ios operating system
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 

Similar to Objective-C for iOS Application Development

Similar to Objective-C for iOS Application Development (20)

Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
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
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
Lecture02
Lecture02Lecture02
Lecture02
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talk
 
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)
 

More from Dhaval Kaneria

Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedureDhaval Kaneria
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedureDhaval Kaneria
 
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1Dhaval Kaneria
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processorDhaval Kaneria
 
Paper on Optimized AES Algorithm Core Using FeedBack Architecture
Paper on Optimized AES Algorithm Core Using  FeedBack Architecture Paper on Optimized AES Algorithm Core Using  FeedBack Architecture
Paper on Optimized AES Algorithm Core Using FeedBack Architecture Dhaval Kaneria
 
PAPER ON MEMS TECHNOLOGY
PAPER ON MEMS TECHNOLOGYPAPER ON MEMS TECHNOLOGY
PAPER ON MEMS TECHNOLOGYDhaval Kaneria
 
VIdeo Compression using sum of Absolute Difference
VIdeo Compression using sum of Absolute DifferenceVIdeo Compression using sum of Absolute Difference
VIdeo Compression using sum of Absolute DifferenceDhaval Kaneria
 

More from Dhaval Kaneria (16)

Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Hdmi
HdmiHdmi
Hdmi
 
open source hardware
open source hardwareopen source hardware
open source hardware
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedure
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedure
 
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1
Manage Xilinx ISE 14.5 licence for Windows 8 and 8.1
 
VERILOG CODE
VERILOG CODEVERILOG CODE
VERILOG CODE
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processor
 
Paper on Optimized AES Algorithm Core Using FeedBack Architecture
Paper on Optimized AES Algorithm Core Using  FeedBack Architecture Paper on Optimized AES Algorithm Core Using  FeedBack Architecture
Paper on Optimized AES Algorithm Core Using FeedBack Architecture
 
PAPER ON MEMS TECHNOLOGY
PAPER ON MEMS TECHNOLOGYPAPER ON MEMS TECHNOLOGY
PAPER ON MEMS TECHNOLOGY
 
VIdeo Compression using sum of Absolute Difference
VIdeo Compression using sum of Absolute DifferenceVIdeo Compression using sum of Absolute Difference
VIdeo Compression using sum of Absolute Difference
 
Mems technology
Mems technologyMems technology
Mems technology
 
Network security
Network securityNetwork security
Network security
 
Token bus standard
Token bus standardToken bus standard
Token bus standard
 

Recently uploaded

Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 

Recently uploaded (20)

Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 

Objective-C for iOS Application Development

  • 1. 1 Introduction to Objective-C and iPhone Development
  • 2. 2 Introduction • Objective-C is implemented as set of extensions to the C language. • It's designed to give C a full capability for object-oriented programming, and to do so in a simple and straightforward way. • Its additions to C are few and are mostly based on Smalltalk, one of the first object-oriented programming languages.
  • 3. 3 Why Objective C • Objective-C incorporates C, you get all the benefits of C when working within Objective-C. • You can choose when to do something in an object-oriented way (define a new class, for example) and when to stick to procedural programming techniques (define a struct and some functions instead of a class). • Objective-C is a simple language. Its syntax is small, unambiguous, and easy to learn • Objective-C is the most dynamic of the object-oriented languages based on C. Most decisions are made at run time.
  • 4. 4 Object-Oriented Programming • The insight of object-oriented programming is to combine state and behavior, data and operations on data, in a high-level unit, an object, and to give it language support. • An object is a group of related functions and a data structure that serves those functions. The functions are known as the object's methods, and the fields of its data structure are its instance variables.
  • 5. 5 The Objective-C Language • The Objective-C language is fully compatible with ANSI standard C • Objective-C can also be used as an extension to C++. • Although C++ itself is a Object-Oriented Language, there are difference in the dynamic binding from Objective-C
  • 6. 6 Objective-C Language (cont.) • Objective-C source files have a “.m” extension • “.h” file is the interface file • For example: – main.m – List.h (Interface of List class.) – List.m (Implementation of List class.)
  • 7. 7 ID • “id” is a data type used by Objective-C to define a pointer of an object (a pointer to the object’s data) • Any type of object, as long as it is an object, we can use the id data type. • For example, we can define an object by: id anObject; • nil is the reserved word for null object
  • 8. 8 Dynamic Typing • “id” data type has no information about the object • Every object carries with it an isa instance variable that identifies the object's class, that is, what kind of object it is. • Objects are thus dynamically typed at run time. Whenever it needs to, the run-time system can find the exact class that an object belongs to, just by asking the object
  • 9. 9 Messages • To get an object to do something, you send it a message telling it to apply a method. In Objective-C, message expressions are enclosed in square brackets [receiver message] • The receiver is an object. The message is simply the name of a method and any arguments that are passed to it
  • 10. 10 Messages (cont.) • For example, this message tells the myRect object to perform its display method, which causes the rectangle to display itself [myRect display]; [myRect setOrigin:30.0 :50.0]; • The method setOrigin::, has two colons, one for each of its arguments. The arguments are inserted after the colons, breaking the name apart
  • 11. 11 Polymorphism • Each object has define its own method but for different class, they can have the same method name which has totally different meaning • The two different object can respond differently to the same message • Together with dynamic binding, it permits you to write code that might apply to any number of different kinds of objects, without having to choose at the time you write the code what kinds of objects they might be
  • 12. 12 Inheritance • Root class is NSObject • Inheritance is cumulative. A Square object has the methods and instance variables defined for Rectangle, Shape, Graphic, and NSObject, as well as those defined specifically for Square
  • 13. 13 Inheritance (cont.) • Instance Variables: The new object contains not only the instance variables that were defined for its class, but also the instance variables defined for its super class, all the way back to the root class • Methods: An object has access not only to the methods that were defined for its class, but also to methods defined for its super class • Method Overriding: Implement a new method with the same name as one defined in a class farther up the hierarchy. The new method overrides the original; instances of the new class will perform it rather than the original
  • 14. Primitive data types from C • int, short, long • float,double • char 14
  • 15. Operators same as C • + • - • * • / • ++ • -- 15
  • 16. Address and Pointers • Same as C • To get address of a variable i &i • Pointer int *addressofi = &I; 16
  • 17. Conditionals and Loops • Same as C/C++ • if / else if/ else • for • while • break • ontinue • do-while for(int i=0; i< 22; i++) { NSLog(“Checking i =“%d”, i); if(i == 12) { break;} } 17
  • 18. 18 for in loop • Introduced in Objective-C 2.0 (“fast enumeration”) for(Item_Type *item in Collection_of_Items) { //do whatever with the item Nslog(@” Looking now at %@”, item); }
  • 19. 19 Functions • Same as C/C++ • return_type functionName(type v1, type v2, ….) { //code of function } Example void showMeInfo(int age) { printf(“You are %d years old”, age); //or use NSLog() }
  • 20. 20 Global and static variables • Same as C/C++ • Global variables defined at top of file • For static variables use keyword static before it static in CurrentYear = 2013;
  • 21. Automatic Reference Counting 21 • Objective C uses ‘AUTOMATIC reference counting' as memory management • keeps an internal count of how many times an Object is 'needed'. • System makes sure that objects that are needed are not deleted, and when an object is not needed it is deleted.
  • 22. 22 Defining a Class • In Objective-C, classes are defined in two parts: – An interface that declares the methods and instance variables of the class and names its super class – An implementation that actually defines the class (contains the code that implements its methods)
  • 23. 23 The Interface • The declaration of a class interface begins with the compiler directive @interface and ends with the directive @end @interface ClassName : ItsSuperclass { instance variable declarations } method declarations @end
  • 24. 24 Declaration • Instance Variables float width; float height; BOOL filled; NSColor *fillColor; • Methods: • names of methods that can be used by class objects, class methods, are preceded by a plus sign + alloc • methods that instances of a class can use, instance methods, are marked with a minus sign: - (void) display;
  • 25. 25 Declaration (cont.) • Importing the Interface: The interface is usually included with the #import directive #import "Rectangle.h" • To reflect the fact that a class definition builds on the definitions of inherited classes, an interface file begins by importing the interface for its super class • Referring to Other Classes: If the interface mentions classes not in this hierarchy, it must declare them with the @class directive: @class Rectangle, Circle;
  • 26. 26 Creating class instances ClassName *object = [[ClassName alloc] init]; ClassName *object = [[ClassName alloc] initWith* ]; – NSString* myString = [[NSString alloc] init]; – Nested method call. The first is the alloc method called on NSString itself. This is a relatively low-level call which reserves memory and instantiates an object. The second is a call to init on the new object. The init implementation usually does basic setup, such as creating instance variables. The details of that are unknown to you as a client of the class. In some cases, you may use a different version of init which takes input: ClassName *object = [ClassName method_to_create]; – NSString* myString = [NSString string]; – Some classes may define a special method that will in essence call alloc followed by some kind of init
  • 27. 27 Example: Hello World #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // insert code here... NSLog(@"Hello, World!"); [pool drain]; return 0; } NSLog() is equivalent to a C printf() Very similar to C C programs are valid in Objective-C
  • 28. 28 Intro to HelloWorld • Objective-C uses a string class similar to the std::string or Java string. It is called NSString. • Constant NSStrings are preceded by @ for example: @”Hello World” • You will notice that NSLog() also outputs time and date and various extra information. • NSAutoreleasePool* pool =[[NSAutoreleasePool • alloc] init]; allocates a lump of memory • Memory must be freed with [pool drain];
  • 29. 29 Some things to note • No line break needed at end of NSLog statements. • NSString constants use C-style variables. • Test this program to see results.
  • 30. 30 @interface @interface ClassName : ParentClassName { declare member variable here; declare another member variable here; } declare method functions here; @end • Equivalent to C class declaration • Goes in header (.h) file • Functions outside curly braces • Don’t forget the @end tag
  • 31. 31 @implementation #import <Foundation/Foundation.h> #include "ComputerScience.h“ @implementation ClassName define method function here; define another method function here; define yet another method function here; @end ● Equivalent to C class function definitions ● Goes in source (.m) file ● Don't forget the @end tag
  • 32. 32 Some things to note • NSObject is the “root” object in Objective-C • No direct access to instance variables so we write some get/set “instance methods” • Instance methods (affect internal state of class) are preceded with a minus sign • “Class methods” (higher level functions) are preceded with a plus sign e.g. create new class • Method return type in parentheses • Semicolon before list of parameters • Parameter type in parenthesis, followed by name
  • 33. 33 Data Structures • Objective-C arrays are similar to C arrays, but you can initialize whole array in a list. • Or just a few indices of the array. The rest are set to 0. • Or mix and match; the example will create an array of size [8]. int values[3] = { 3, 4, 2 }; char letters[3] = { 'a', 'c', 'x' }; float grades[100] = {10.0,11.2,1.1}; int array[] = {[3]=11,[2]=1,[7]=0};
  • 34. 34 Multi-dimensional Arrays • Can be initialized by using subset notation with braces. Note no comma after second subset. • Subset braces are optional, the compiler will fill in blanks where it can as with 1D arrays. int array[2][3] = { { 0, 3, 4}, { 1, 1, 1} }; int array[2][3] = {0, 3, 4, 1, 1, 1};
  • 35. 35 Frameworks • UIKit.framework for developing standard iOS GUIs (buttons etc.) • UITextField (user-entered text that brings up the keyboard) • UIFont • UIView • UITableView • UIImageView • UIImage • UIButton (a click-able button) • UILabel (a string of text on-screen) • UIWindow (main Window on iPhone)