Header File
Browse / Objective-C Cheatsheet
Objective-C Cheatsheet
A quick reference for Objective-C syntax, data types, control structures, and object-oriented programming concepts. This cheat sheet provides a concise overview for both beginners and experienced developers.
Fundamentals
Basic Syntax
|
|
|
|
Implementation File |
|
|
Comments |
|
|
NSLog |
|
|
Variables |
|
Data Types
|
Integer |
|
|
Float |
|
|
Double |
|
|
Boolean |
|
|
Character |
|
|
NSString |
|
Operators
|
Arithmetic |
|
|
Assignment |
|
|
Comparison |
|
|
Logical |
|
|
Bitwise |
|
Control Structures
Conditional Statements
|
If Statement
|
|
If-Else Statement
|
|
Else If Statement
|
Switch Statement
|
Looping
|
For Loop
|
|
While Loop
|
|
Do-While Loop
|
|
For-In Loop (Fast Enumeration)
|
Object-Oriented Programming
Classes
|
Defining a Class (.h file)
|
|
Implementing a Class (.m file)
|
Properties
|
Defining Properties in .h file
|
|
Synthesizing Properties in .m file (Prior to Xcode 4.4)
|
|
Accessing Properties
|
Methods
|
Instance Method |
|
|
Class Method |
|
|
Method Implementation |
|
Protocols
|
Defining a Protocol
|
|
Adopting a Protocol
|
Memory Management
Automatic Reference Counting (ARC)
|
ARC automates memory management by tracking object ownership using reference counting. The compiler inserts retain and release calls as needed. To enable ARC, set the compiler flag |
|
When ARC is enabled, you no longer need to manually call |
Strong and Weak References
|
Strong Reference |
A strong reference increases the retain count of an object. It keeps the object alive as long as the strong reference exists. |
|
Weak Reference |
A weak reference does not increase the retain count. When the object is deallocated, the weak reference is automatically set to |
|
Unretained Reference |
An unretained reference is similar to a weak reference, but it is not set to |
Autorelease Pool
|
An In ARC, you rarely need to use Example:
|