Why I write automated tests

Leave a comment

Why I write automated tests.

I write automated tests for a variety of reasons. For one they tell me when I break things. Secondly, having automated tests enables me to go fast. I can make changes with confidence. I am free to aggressively refactor my design. And I don’t stress about breaking the important stuff because I know the automated tests are there to back me up. They are like my shield and my armour.

But really, to me, automated tests are about leverage. They allow me to leverage myself in greater ways that wouldn’t be possible if they weren’t there. I can spend less time regression testing. More time adding new features, improving the testing while doing the one other kind of testing that’s really important – exploratory. These are things things the computer can’t do. Only I can.

So for me automated tests are about leverage. They give us a way to leverage ourselves and our teams further, while giving us all back the one thing we crave. Time.

How to add iOS Xcode subprojects abbreviated

1 Comment

If you want to add another iOS project to your existing subproject, at a minimum do this. Find the project you want to add

Screen Shot 2017-02-23 at 1.19.43 PM.png

Drag it into your project

Screen Shot 2017-02-23 at 1.20.28 PM.png

Goto the target you want to add it to -> Build Phases.

Add Target Dependency (hit the + sign)

Screen Shot 2017-02-23 at 1.21.54 PM.png

Link Binary With Libraries (+ sign)

Screen Shot 2017-02-23 at 1.22.29 PM.png

Build/Compile. You should now be good to go.

Links that help



How to quickly clear derived data

Leave a comment

Xcode -> Preferences -> Locations -> little grey arrow that is hard to see

Screen Shot 2017-02-23 at 1.18.26 PM.png

Screen Shot 2017-02-23 at 1.18.41 PM.png

Then physically delete the directory in finder

Screen Shot 2017-02-23 at 1.19.00 PM.png

How to share data App Extension

Leave a comment

How to share data between App Extension and Host

Since app extensions run as part of a host application rather than their containing app (i.e. your app extension runs in somebody elses app), data sharing isn’t automatic.

App extensions and hosts can share data via App Groups. App Groups are shared containers both App Extensions and Hosts can use to communicate with each other since no direct communication is allowed.

Setting up an App Group

App Groups are the scheme iOS uses to allow different apps to share data. If you have the right entitlements and proper provisioning, they can access a shared directory outside their normal iOS sandbox.

Create a new SingleView app.

Screen Shot 2017-02-14 at 1.29.21 PM.png

Go Capabilities and turn on App Groups.

Screen Shot 2017-02-14 at 1.29.50 PM.png

Screen Shot 2017-02-14 at 1.29.54 PM.png

Now you can share data like this.

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
    [myDefaults setObject:@"foo" forKey:@"bar"];
    NSLog(@"\n\nWrote it!\n\n\n");

Add an App Extension

Now let’s add an app extension and try this out. New Target -> iMessage Extension.

Note: This will automatically setup a sub bundle id that should work for you out of the box. Bundle ids are important and this must be nested.

Screen Shot 2017-02-14 at 1.31.31 PM.png

It will also create an entitlements file

Screen Shot 2017-02-14 at 1.31.36 PM.png

Turn on App Groups for your newly created App Extension

Screen Shot 2017-02-14 at 1.32.09 PM.png

And now try reading something from NSUserDefaults written by your container app.

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
    NSString *value = [myDefaults objectForKey:@"bar"];
    NSLog(@"\n\n\nvalue: %@\n\n\n", value);

 Screen Shot 2017-02-14 at 1.33.26 PM.png

Links that help



How to animate view iOS

Leave a comment

- (void)showErrorView
    if (self.errorView.hidden) {
        self.errorView.alpha = 0.0;
        self.errorView.hidden = NO;

        [UIView animateWithDuration:0.3 animations:^{
            self.contentView.alpha = 0.0;
            self.errorView.alpha = 1.0;
        } completion:^(BOOL finished) {
            self.contentView.hidden = YES;
            self.noResultsView.hidden = YES;
            self.offlineView.hidden = YES;

Beautiful code is good method composition

Leave a comment

Was listening to a podcast with DHH on Tim Ferris show and I really like his definition of beautiful code.

Basically said it’s code where all the methods and abstractions in a class are at the same level. Some methods aren’t doing really low level things. Others aren’t too high. They are all at the same level of abstraction.

Good way to describe any nice API.

For example you can do this:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupDelegates];
    [self setupLayouts];
    [self setupSearchBar];
    [self setupReachability];
    [self displayTracks];

Or you can do this

- (void)viewDidLoad {
    [super viewDidLoad];
    self.searchBar.delegate = self;
    self.collectionView.delegate = self;
    self.collectionView.collectionViewLayout = self.collectionFlowLayout;
    [self setupSearchBar];
    [self setupReachability];
    [self displayTracks];

See the difference? The methods are not all at the same level of abstraction. Which makes the code harder to read.

IBOutlets should always be weak

Leave a comment

Pair just reminding me that IBOutlets should always be weak.

But if you create an object and programmatically yourself they can be strong.

Older Entries Newer Entries

%d bloggers like this: