Static properties

extern NSString *const kStartKey;
extern NSString *const kEndKey;


NSString *const kStartKey = @"start";
NSString *const kEndKey = @"end";

Image compression
Network latency

Design sizes

Cmd + Shift + Right Click to select subviews in storyboard
Alt + = to re-layout elements autolayout
Shift + Right Click Select subviews in storyboard

Simple initializer

- (instancetype)init
    self = [super init];
    if (self) {
        // do init work here, e.g. _myIvar = someParam;
    return self;

@interface SPTAppRemoteContentAPIImplementation : NSObject <SPTAppRemoteContentAPI>

 * Initializes a new content API.
 * @discussion This is the designated initializer.
 * @param client The client responsible for sending and receiving messages with Spotify app.
- (instancetype)initWithClient:(SPTAppRemoteWAMPClient *)client NS_DESIGNATED_INITIALIZER;

#pragma mark Unavailable Initializers

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;



Simple Mock

@interface LibraryApiTests : FooTestCase
@property (nonatomic, strong) PlaybackStatus *mockStatus;

@interface CallMessageHandler()
- (NSDictionary *)constructMessage:(PlaybackStatus *)playbackStatus;

@implementation LibraryApiTests

- (void)setUp
    self.mockStatus = mock([PlaybackStatus class]);

- (void)testGetSavedPayload
    // given
    [given([self.mockStatus saved]) willReturnBool:YES];
    [given([self.mockStatus canSave]) willReturnInt:0];
    [given([self.mockStatus trackURI]) willReturn:[NSURL URLWithString:@""]];

    // when
    MessageHandler *handler = [[MessageHandler alloc] init];
    NSDictionary *payload = [handler constructMessage:self.mockStatus];

    // then
    XCTAssertEqual([payload[key1] intValue], 1);
    XCTAssertEqual([payload[key2] intValue], 0);
    XCTAssertEqual(payload[key3], @"");



 * The @c PlayerStateDelegate is used to get notifications.
@protocol PlayerStateDelegate <NSObject>

 * Called when the player state has been updated.
 * @param playerState The new player state.
- (void)playerStateDidChange:(id<PlayerState>)playerState;


 * The @c SPTAppRemotePlayerAPI is used to ...
@protocol SPTAppRemotePlayerAPI <NSObject>

/// The delegate receiving player state updates
@property (nonatomic, weak) id<PlayerStateDelegate> delegate;

- (void)play:(NSString *)entityIdentifier callback:(nullable RemoteCallback)callback;




p (BOOL)[libraryState isAdded];
NSError *error = [NSError errorWithDomain:@"" code:0 userInfo:nil];
NSLog(@"%s #%d: Error fetching access token with error:%@", __FILE__, __LINE__, error);
NSLog(@"%@", @(__FUNCTION__));

Xcode fails to attach to simulator

sudo purge

or flip simulator


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [weakSelf showSearchKeyboard];


[self performSelector:@selector(becomeFirstResponder) withObject:textField afterDelay:0.5f];

Main thread

 dispatch_async(dispatch_get_main_queue(), ^{

Error codes

Undefined symbols for architecture x86_64 reachability

Means you need to import a library into your project file (i.e. SystemConfiguration for reachability).

How to see who calls what method

Screen Shot 2017-07-12 at 2.47.31 PM.png

Links that help

5 Comments (+add yours?)

  1. Jody
    Oct 10, 2012 @ 23:26:44

    Something that always bothered me about Apple’s APIs, or at least examples of their usage, is the messyness of implementation. Is it lack of OO design?

    i.e. The table view delegate from above implements the cellForRowAtIndex, and this one method is responsible for dequeueing or creating a cell (factory) as well as populating it (builder/strategy?)


    • JR
      Oct 11, 2012 @ 19:12:48

      I’ve heard arguments both ways.

      Some people I know love the API. They think it’s one of the most mature, stable platforms they’ve ever worked on.

      Others have thoughts similar to you. They think certain abstractions leak responsibility and are messy from an OO point-of-view.

      I personally like the API. But I would be the first to agree it isn’t perfect (the ALAssetLibrary I find particularly cumbersom).

      Thanks for the comment Jody.


  2. rob v
    Jan 03, 2013 @ 02:24:51

    some of your examples would be great to add into the code snippets library in the XCode inspector panel as user snippet, even if temporarily, until they become familiar. thanks for posting


  3. chandresh maurya
    Jun 11, 2014 @ 17:24:17

    how to use nsmutablearray to add multiple images in a single use of cell


  4. chandresh maurya
    Jun 11, 2014 @ 17:25:26

    how to use Ns mutable array to add multiple images in a single row of cell for ios


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s