Objective C Lec1
Objective C Lec1
Presented By
Safiya Fikry
Lecture One
Agenda
• Introduction.
• Objective-C.
• Classes & Objects.
• Methods.
• Choosing Names
• Data Types.
• Loops.
• Conditions.
• Comments.
[ Introduction ]
Apple History
How it all started !!
Apple History
Original Logo
Apple I
Apple II
Apple III
Apple Inc.
Apple Products
• Computers
▪ MacBook Pro
▪ MacBook Air
▪ iMac
▪ Mac mini
▪ Mac Pro
Apple Products Cont.
• Mobile devices
▪ iPhone
• Other
▪ Home Pods
▪ Apple TV
▪ iPod
▪ iWatch
▪ Vision
Apple Products Cont.
• Operating Systems:
• Ease of marketing
▪ Upload to the store
▪ Customers will try, no convincing is needed
• In Egypt:
▪ Growing market
▪ Rare developers
[ Development Environment ]
Development Environment
• NEXTSTEP environment became the basis for the next major release of Apple’s
operating system, OS X (Cocoa)
• Today: Objective-C and Swift are the native languages for developing Mac OS X
and iOS applications
[ Program Structure ]
Program Structure
• Objective-C source files are identified by the .m file
extension.
• Program entry point is: Main function
• Usually the interface section is in a .h file, and the implementation section in a .m file
• However both could be defined in one file
• More than one class could be defined in the same file
Interface
• Syntax
Example
Implementation
• Note: No need for defining parent class here as it’s already defined in the
interface section
[ Methods ]
Methods
▪ Instance methods
• Syntax
• Allocating memory:
Memory
• Initialize Object:
Heap
classA Object
• Combined
• Names in Objective-C must begin with a letter or underscore(_), and they can be
followed by any combination of letters (upper - or lowercase), underscores, or the
digits 0–9
• Instance variables, objects, and method names, on the other hand, typically begin
with lowercase letters
• Capital letters are used inside names to indicate the start of a new word
Choosing Names Cont.
▪ sum
▪ pieceFlag
▪ i
▪ myLocation
▪ numberOfMoves
▪ sysFlag
▪ ChessBoard
Choosing Names Cont.
• On the other hand, the following names are not valid for the stated reasons:
• The vast majority of Objective-C’s primitive data types are adopted from C
▪ char
▪ int
▪ float
▪ double
Data Types
• Data types are common on many programming languages, but they do not
represent the same size as it depends on the machine
• In general, size of: char < int < float < double
[Loops]
For Loop
• Example
For Loop Cont.
• Example
While Loop Cont.
• Condition based
• Number of iterations is not known
• Infinite loop due to:
▪ Condition is unreachable
• Condition is checked first and then the body is executed
Do - While Loop
• Example
Do - While Loop Cont.
• Using continue:
▪ Skips the current iteration and jumps to the next one
• Using break:
▪ Skips the whole body of the loop
[ Conditions ]
if Statement
• Example
if - else Statement
• Example
Switch-Case
Switch-Case Example
Ternary Operator
• Example
• Use “printf”, and NSLog and state what is the difference between both.
2.Rectangle
• The rectangle’s dimension should be obtained from the user, result should be
displayed back using the command prompt
2.Rectangle Cont.
• Create a program that represent complex number and has two methods to add
and subtract complex numbers:
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*