Anda di halaman 1dari 3

12/11/2015

Objective-C

Objective-C
CS206 PROGRAMMING LANGUAGES

Why use Objective-C?


It is the primary programming language used when
writing software for OS X and iOS, which explains its
rapid rise in popularity after the iPhone appeared.
One of the programming languages which has a
combination of imperative and object-oriented features.
Objective-C is a strict superset of C
it inherits the syntax, primitive types, flow control statements of C
it adds syntax for defining classes and methods

The History of Objective-C


The year was 1986.

Obj-C History (continued)


Tom Love and Brad Cox designed Objective-C
They had been exposed to Smalltalk while at ITT Corporation

The C programming language had been in use for about


15 years.
C++ was just new and not yet popular.

The Smalltalk programming language introduced a new


concept in programming called object-oriented
programming.

Obj-C History (continued)


A few years later, Steve Jobs
founded NeXT
licensed and standardized Objective-C as the primary language to
be used to write their new operating system, NeXTstep, for the
NeXT computer

Eventually, the NeXT computer project failed.


Then, NeXT was purchased by Apple.
This resulted to the absorption of the NeXTstep operating system
and its eventual evolution into Mac OS X, which was written in
Objective-C.

Eventually, the two formed a company to commercialize


this extension of C programming language and market
them to developers.

Among all the programming languages that were created


by adding support for object-oriented programming to an
imperative language, Objective-C is the only one to use
the Smalltalk syntax for that OOP support.

Objective-C and Java


Objective-C has influenced many other programming
technologies. One of them is Java.
Reason:
When NeXT partnered with Sun Microsystems to
develop the OpenStep platform, Objective-C is the
language they used.
When NeXT began to fail, Sun decided to develop their
own language and cross-platform development kit, Java.
The engineers that worked on Java were intimately
familiar with Objective-C because they had been using it
prior to developing Java.

12/11/2015

Names in Objective-C

Class Names in Objective-C

CaSe SeNSiTIVE
written in camelNotation

Classes are named uniquely not only within the code in a


project, but also across any frameworks or bundles that
are to be included.
Framework classes use two-letter prefixes. These were
reserved by Apple.

Classes are in camel notation, but first letter must be in Uppercase

Names that are defined in other program units of


Objective-C, called libraries, can be made visible to a
program only if they are explicitly imported.

User-defined classes should use three-letter prefixes.

Bindings in Objective-C

Scopes in Objective-C

dynamic binding binding first occurs during run time or


can change in the course of program execution

Objective-C
does not nested subprograms.

dynamic type binding any variable can be assigned any


type value

allows global variables


features static and dynamic scoping

Scalar Data Types in Obj-C


Scalar Data Types in Obj-C
basic form of variables in Objective-C.
a type of value that can hold only one value at a time.
Most of these types are also shared with C and C++, but
there are a couple that are unique to Objective-C.

Type

Commonly used Scalar Variables


Description

232
1
2
An
integer
value
between
0
and
232
unsigned int
A floating point value between 224
float

int

An integer value between

double

A floating point value between

long
long long
char
BOOL

NSInteger
NSUInteger

232

2
An integer value varying in size from 32-bit to 64-bit depending on
architecture.
A 64-bit integer
A single character; Technically its represented as an int
A Boolean value, can be either YES or NO
When compiling for 32-bit architecture, same as an int,

when compiling for 64-bit architecture, 232


When compiling for 32-bit architecture, same as an unsigned int,
when compiling for 64-bit architecture, value between 0 and 264

12/11/2015

Derived Data Types in Obj-C


complex data types from combining basic data types.
pointer a data type that points to the location where
data is stored
Example:

int *ptrValue;

struct a combination of several data types that creates a


new custom data type
Example:

struct XYcoordinate {int x; int y;}

enum allows the programmer to define a new data type


with enumerations (range of values for a variable)
Ex. typedef {Mon, Tues, Wed, Thurs, Fri} Weekday;

Anda mungkin juga menyukai