iOS

Static properties
header.h

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

body.m

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

Tools
Image compression
Network latency

Design sizes
https://designcode.io/iosdesign-guidelines
http://ivomynttinen.com/blog/the-ios-7-design-cheat-sheet
https://agilewarrior.wordpress.com/2017/03/22/xcode-trouble-shooting-guide/

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;
}
NS_ASSUME_NONNULL_BEGIN

@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;

@end

NS_ASSUME_NONNULL_END

Simple Mock


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

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

@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:@"track.xxx"]];

    // 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], @"track.xxx");
}
@end

Protocols

NS_ASSUME_NONNULL_BEGIN

/**
 * 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;

@end

/**
 * 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;

@end

NS_ASSUME_NONNULL_END

Misc

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

Favor

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

over

[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

https://agilewarrior.wordpress.com/2016/04/11/appcode-formatting/
https://agilewarrior.wordpress.com/2016/04/07/appdoc-examples/
https://agilewarrior.wordpress.com/2016/04/07/objective-c-object-initialization/
https://agilewarrior.wordpress.com/2016/03/24/nice-pattern-for-defining-nserror-constants/
https://agilewarrior.wordpress.com/2016/03/16/class-vs-import-objective-c/
https://agilewarrior.wordpress.com/2016/03/16/how-to-use-nullable-objective-c/
https://agilewarrior.wordpress.com/2016/03/07/autolayout-basics-1/
https://agilewarrior.wordpress.com/2016/03/07/nullability-and-objective-c/
https://agilewarrior.wordpress.com/2016/03/07/objective-c-nil-nil-null-nsnull/
https://agilewarrior.wordpress.com/2016/02/25/synthesizing-properties-in-protocols/
https://agilewarrior.wordpress.com/2016/02/25/how-to-add-support-for-subclassing-objective-c/
https://agilewarrior.wordpress.com/2016/02/25/how-to-link-an-embedded-framework-in-xcode-ios/
https://agilewarrior.wordpress.com/2016/02/24/how-to-add-external-xcode-project-to-existing-on/
https://agilewarrior.wordpress.com/2016/02/19/how-to-see-what-processes-running-on-iphone-from-xcode/
https://agilewarrior.wordpress.com/2016/02/12/protocol-delegate-example-ios/
https://agilewarrior.wordpress.com/2016/02/04/how-to-define-inner-class-objective-c/
https://agilewarrior.wordpress.com/2016/02/01/how-to-view-crash-logs-macos/
https://agilewarrior.wordpress.com/2015/11/24/how-to-make-generic-ios-library/
https://agilewarrior.wordpress.com/2015/11/13/ios-test-classes-not-running/
https://agilewarrior.wordpress.com/2015/10/20/ios-objective-c-trick-to-exposing-private-properties-and-methods-in-your-tests/
https://agilewarrior.wordpress.com/2015/10/20/ios-objective-c-trick-to-expose-private-methods-and-properties/
https://agilewarrior.wordpress.com/2015/10/01/coding-guidelines-for-cocoa/
http://stackoverflow.com/questions/5191487/objective-c-forward-class-declaration
http://stackoverflow.com/questions/32452889/difference-between-nullable-nullable-and-nullable-in-objec

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?)

    Reply

    • 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.

      Reply

  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

    Reply

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

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

    Reply

  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

    Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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