Objective C Cheat Sheet
Objective C Cheat Sheet
Method
Headers
Definition:
The
first
line
of
a
method;
The
return
type,
method
name
,
and
parameters
are
stated.
Examples:
-(returnType)methodName
-(returnType)methodName:
(dataType)param1
-(returnType)methodName:
(dataType)param1
withParam:
(dataType)param2
Similar
To
C/C++
/Java:
returnType
methodName()
returnType
methodName(param1)
returnType
methodName(param2)
Interface Definition: Declaration in which class name, inheritance, variables, method names, and property is declared. Example: @interface ClassName: ParentClass <Protocol> { dataType variableName; } @property data; -(returnType)methodName: (dataType) param1 @end
Implementation
Definition:
Declaration
in
which
the
actual
class
implementation
is
defined.
Example:
This
is
where
you
implement
the
actual
class.
@implementation
ClassName
@synthesize
data;
-(returnType)methodName:
(dataType)
param1
{
...
Method
Details
...
}
@end
Import
Definition:
Importing
is
the
inclusion
of
the
source
code
of
a
specified
file
within
the
current
file.
Examples:
#Import
Class.h
#Import
<Class.h>
#Import
<director/Class.h>
Self
Definition:
Identifier
for
the
current
class
instantiation.
Example:
[self
keyword]
Similar
to
Java/C++
this
keyword
Categories
Definition:
A
way
of
sectioning
code.
Categories
are
used
for
better
code
organization,
and
can
be
used
to
add
methods
to
classes
for
which
you
do
not
have
the
source
code.
@interface
ClassName
(category)
-(returnType)methodname;
@end
@implementation
NSString
(MyCoolAddition)
-
(returnType)methodName
{
Method
Details
}
@end
Protocol
Definition:
Class
from
which
structure
is
inherited,
not
implementation.
Example:
@implementation
className
<protocol>
Definition: @property declarations are declarations of a property used for automatic getter and setter creation. Definition: @synthesize declarations are implementions of a property used for automatic getter and setter creation. Example: in interface: @property dataType variableName in implementation: @synthesize variableName
Inheritance
Definition:
The
formation
of
a
new
class
using
an
already
defined
class
and/or
protocol.
Examples:
ClassName:
ParentClass
ClassName:ParentClass
<Protocol>
ClassName
<Protocol>
Similar
To:
Java:
ClassName
extends
ParentClass
implements
Interface
C++:
ClassName:
Parentclass
<interface>
Id
Definition:
Keyword
used
as
a
generic
identifier
for
any
class.
Example:
id
name
Similar
To
Object
Keyword
in
Java
and
void*
in
C++