| name | objective-c |
| description | Google's official Objective-C style guide. Covers naming conventions, formatting, memory management, properties, protocols, categories, and Objective-C best practices. |
Google Objective-C Style Guide
Official Google Objective-C coding standards for consistent iOS/macOS code.
Golden Rules
- Use ARC — Automatic Reference Counting (no manual retain/release)
- Descriptive naming — clarity over brevity; method names read like sentences
- Prefix class names — avoid namespace collisions (2-3 letter prefix)
- Use properties — prefer
@property over direct instance variables
- Nullability annotations — mark
nullable/nonnull on APIs
- Use modern Objective-C — literals, subscripting, generics
- Follow Apple conventions — consistency with Cocoa frameworks
Quick Reference
Naming Conventions
| Element | Convention | Example |
|---|
| Classes | PrefixUpperCamelCase | GTMUserService |
| Protocols | PrefixUpperCamelCase | GTMUserServiceDelegate |
| Methods | lowerCamelCase | - (void)getUserById:(NSInteger)userId |
| Properties | lowerCamelCase | userCount, firstName |
| Local variables | lowerCamelCase | localUser |
| Constants | kPrefixUpperCamelCase | kGTMMaxRetries |
| Enums | PrefixUpperCamelCase | GTMDirection |
| Enum values | PrefixUpperCamelCase | GTMDirectionNorth |
Class Interface
@interface GTMUserService : NSObject
@property(nonatomic, readonly) NSInteger userCount;
@property(nonatomic, copy, nullable) NSString *currentUserName;
- (nullable GTMUser *)userWithId:(NSInteger)userId;
- (void)fetchUsersWithCompletion:(void (^)(NSArray<GTMUser *> *_Nullable users,
NSError *_Nullable error))completion;
@end
Properties
@property(nonatomic, strong) NSMutableArray<GTMUser *> *users;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, assign) BOOL isLoading;
@property(nonatomic, weak) id<GTMUserDelegate> delegate;
@property(nonatomic, readonly) NSInteger count;
Methods
- (nullable GTMUser *)userWithFirstName:(NSString *)firstName
lastName:(NSString *)lastName;
- (void)setUser:(GTMUser *)user forKey:(NSString *)key;
+ (instancetype)serviceWithBaseURL:(NSURL *)baseURL;
- (GTMUser *)usr:(NSString *)fn ln:(NSString *)ln;
Modern Objective-C Literals
NSArray *colors = @[@"red", @"green", @"blue"];
NSDictionary *config = @{@"host": @"localhost", @"port": @8080};
NSNumber *count = @42;
NSNumber *enabled = @YES;
NSString *first = colors[0];
NSString *host = config[@"host"];
NSArray *colors = [NSArray arrayWithObjects:@"red", @"green", nil];
Protocols and Delegates
@protocol GTMUserServiceDelegate <NSObject>
@required
- (void)userService:(GTMUserService *)service
didLoadUser:(GTMUser *)user;
@optional
- (void)userService:(GTMUserService *)service
didFailWithError:(NSError *)error;
@end
Memory Management with ARC
@implementation GTMUserService {
NSMutableArray<GTMUser *> *_users;
}
- (instancetype)init {
self = [super init];
if (self) {
_users = [[NSMutableArray alloc] init];
}
return self;
}
@end
__weak typeof(self) weakSelf = self;
[self fetchData:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) return;
[strongSelf processResults];
}];
Nullability Annotations
NS_ASSUME_NONNULL_BEGIN
@interface GTMUser : NSObject
@property(nonatomic, copy) NSString *name;
@property(nonatomic, copy, nullable) NSString *email;
- (nullable GTMUser *)userWithId:(NSInteger)userId;
@end
NS_ASSUME_NONNULL_END
Common Mistakes
| Mistake | Correct Approach |
|---|
| Short/abbreviated names | Use descriptive, sentence-like names |
| No class prefix | Use 2-3 letter prefix to avoid collisions |
| Direct ivar access | Use @property and synthesized accessors |
| Missing nullability annotations | Use NS_ASSUME_NONNULL_BEGIN/END |
| Manual retain/release | Use ARC |
| Old collection syntax | Use modern literals @[], @{} |
| Strong delegate references | Use weak for delegates |
When to Use This Guide
- Writing new Objective-C code
- Maintaining legacy Objective-C iOS/macOS apps
- Code reviews
- Onboarding new team members
Install
npx skills add testdino-hq/google-styleguides-skills/objective-c
Full Guide
See objective-c.md for complete details, examples, and edge cases.