100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Objective-C Cheat Sheet

Objective-C Cheat Sheet

Fundamental Objective-C syntax covering classes, properties, messaging, ARC memory management, and protocols.

2 PagesIntermediateApr 12, 2026

Hello World

A minimal Objective-C program.

objectivec
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        NSString *greeting = @"Hello, World!";        NSLog(@"%@", greeting);    }    return 0;}

Interface & Implementation

Declaring a class with properties and methods.

objectivec
// Person.h@interface Person : NSObject@property (nonatomic, strong) NSString *name;@property (nonatomic, assign) NSInteger age;- (instancetype)initWithName:(NSString *)name age:(NSInteger)age;- (void)sayHello;@end// Person.m@implementation Person- (instancetype)initWithName:(NSString *)name age:(NSInteger)age {    self = [super init];    if (self) {        _name = name;        _age = age;    }    return self;}- (void)sayHello {    NSLog(@"Hi, I'm %@", self.name);}@end

Properties & Messaging

Core object and messaging syntax.

  • [obj method]- Square-bracket message send syntax
  • @property (nonatomic, strong)- Declares an object property, auto-synthesizes getter/setter
  • self / super- Reference to the current instance / the superclass
  • nil- Null object pointer; messaging nil is a safe no-op
  • [[Person alloc] init]- Allocate memory, then initialize an instance
  • id- Generic object pointer type, any Objective-C object

Memory Management (ARC)

Automatic Reference Counting basics.

  • ARC- Automatic Reference Counting; the compiler inserts retain/release calls for you
  • strong- Owns the referenced object, keeps it alive
  • weak- Non-owning reference, automatically becomes nil when the object is deallocated
  • retain/release- Managed automatically under ARC; do not call manually in ARC code
  • @autoreleasepool- Block that drains autoreleased objects at its end

Protocols

Defining and conforming to a protocol.

objectivec
@protocol Greetable <NSObject>- (void)greet;@optional- (void)farewell;@end@interface Robot : NSObject <Greetable>@end@implementation Robot- (void)greet {    NSLog(@"Beep boop, hello!");}@end
Pro Tip

Prefer weak references for delegate properties (@property (nonatomic, weak) id<Delegate> delegate;) to avoid retain cycles between parent and child objects.

Was this cheat sheet helpful?

Explore Topics

#ObjectiveC#ObjectiveCCheatSheet#Programming#Intermediate#HelloWorld#InterfaceImplementation#PropertiesMessaging#MemoryManagementARC#OOP#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet