Objective-C Style Guide
NSString *text
unless it's NSString * const Text
idx
/ jdx
instead of i
/ j
in for loops.url
or urlString
). Otherwise, they should be all caps when occurring elsewhere in the method name, or as a class name (ex: handleStripeURLCallbackWithURL
or STPAPIClient
)_
, e.g. - (void)_doPrivateStuff
and id _internalVariable
. This is not required for private properties which should not include an underscore (this is to distinguish them from their underlying variable which automatically has an _
prefix).else if
and else
on the same line as the preceding closing curly brace:if (condition) return YES;
switch
statements for enums should contain an entry for each value and avoid using default
NSString
, NSDictionary
, NSArray
, NSNumber
:STP
:stripe-ios/Stripe/
stripe-ios/Tests/Tests/
stripe-ios/Example/Basic Integration/Basic Integration/
stripe-ios/Example/Non-Card Payment Examples/Non-Card Payment Examples/
stripe-ios/Stripe/PublicHeaders/
for Cocoapods and Swift Package Manager compatibility@class
for everything elseNS_ASSUME_NON_NULL_BEGIN
/ NS_ASSUME_NON_NULL_END
in headers. NS_ASSUME_NON_NULL_BEGIN
/ NS_ASSUME_NON_NULL_END
should also be used in implementation (.m
) filesstp_
to avoid collision:STPSource.m
.+Private.h
file. Ex: STPSource+Private.h
.assign
, readwrite
, strong
)copy
for classes with mutable counterparts such as NSString
, NSArray
, NSDictionary
@synthesize
and @dynamic
on separate lines for shorter diffsself.foo
) instead of their corresponding instance variables (_foo
). Instance variables should only be accessed directly in initializer methods (init
, initWithCoder:
, etc…), dealloc
methods, and within custom getters and setters. For more information, see Apple’s docs on using accessor methods in initializer methods and dealloc..#define
to define a block of code -- #define
code is very difficult to debug#pragma mark - <text>
and #pragma mark <text>
to group methods In large implementation files: