A Chemist Coding iOs

by Christopher Brandow

Husband, Parent, iOs Developer, Chemist, PEN, used to exercise.

Read this first

Faster build times by leveraging multi-core CPU!

How in the world is this not the default and how have I not heard of this before?!?

Buried in this helpful blog post about making your XCode life easier, is this tip:

Faster build times by leveraging multi-core CPU ?

defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks `sysctl -n hw.ncpu`

I tested it on my work project. I cleaned, cleaned the build folder and restarted XCode in both cases. Results:

Before After
23.4 s 13.9 s

Considering how often I build this project in a day (>20 times?) that is a great return on investment, even if it is only minutes.

 Caveats

  1. I am pretty much just cutting and pasting here. So read more if you want to be safe. Messing with defaults regarding cores like that can definitely impact battery life and other stuff.
  2. I don’t know what the default value was. I don’t know how to restore it. I don’t know if/when

Continue reading →


Facebook Friend Suggestions and Privacy Porosity (via Android IRL Friends?)

A few months ago, my wife came to me asking how Facebook would know to suggest a couple of people that she had spoken to professionally on her phone. I asked if they had been in the same location, or if they were in her contacts, or if you had mutual Facebook friends. “Maybe, yes”, and “No”, and “No” were her replies. I checked her privacy settings, and sure enough the OS privacy settings indicate that , and I think that . We talked it through, and I couldn’t find anything online about how this could be happening, but we also didn’t know the nature of the other people’s phones.

Then just the other day, I got a friend suggestion for a person that I had spoken to on the phone and texted with. We had also been in the same location a number of times. And we don’t have any direct mutual “friends”.

I do know that this person uses an Android phone, and what little research I did do, indicates

Continue reading →


Finding From Where A Method Is Being Called

The linked SO post has a nice method for logging where an Objective-C method is being called from. Simple but helpful.

    NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
    // Example: 1   UIKit                               0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
    NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString  componentsSeparatedByCharactersInSet:separatorSet]];
    [array removeObject:@""];

    NSLog(@"Stack = %@", [array objectAtIndex:0]);
    NSLog(@"Framework = %@", [array objectAtIndex:1]);
    NSLog(@"Memory address = %@", [array objectAtIndex:2]);
    NSLog(@"Class caller = %@", [array objectAtIndex:3]);
    NSLog(@"Function caller = %@", [array objectAtIndex:4]);

Continue reading →


CSV to Multi-Markdown Tables

One person noticed yesterday’s yak-shaving and liked it, which was all the excuse I needed to shave it some more. But I am good to go for now, though this still is still fairly fragile: you have to select only the table lines, there’s no way to escape a comma if you want it in a particular entry, it won’t catch if there are different number of items on each line, etc.

Here is the downloadable workflow .

I cleaned up the code in ways that were useful learning exercises for me and added support for >, <, = as separator indicators

so this:

one, two and a half, three and a quarter
four, five, six

still outputs to this:

|  one | two and a half | three and a quarter |
|  :---: |  :---: |  :---: |  
|  four | five | six | 

but now this:

one, two and a half, three and a quarter
>, =, <
four, five, six

outputs this:

|  one | two and a half | three and a quarter |
| ----: | :---: |

Continue reading →


A Quick Swift Script Yak Shave

[Updated Version with downloadable OS X service]
In the process of writing a longer post yesterday, I wanted to add a markdown table, and was once again annoyed at the mild PITA that it is to use pipe characters and then the formatting characters a lá:

|    title    |   title2   |  
| :---------: | :--------: |  
|  entry one  |  entry two |  
| entry three | entry four |  

Being aware of Brett Terpstra’s excellent Markdown Services that have a table cleanup function, but actually writing the da** tables is kind of annoying, so I in classic Yak-Shaving fashion, I decided to write a simple Swift script that would turn the following into the format above. Then make that into an OS X service.

title, title2
entry one, entry two
entry three, entry four

It really wasn’t that tricky, and probably would have been at least as easy using python or ruby, but ¯_(ツ)_/¯. (<– typed using

Continue reading →


Possible Future macOS Names

Just for funnies. Others have done this as well before

We’ve had:

Maverics
Yosemite
El Capitan
Sierra

 Criteria as I see them

  1. In California
  2. Natural Feature or Area
  3. Proper name.
  4. Has to sound good when spoken.
  5. Well known, or famous within a niche

 Bad or doesn’t sound right

Death Valley
Long Beach
“Anything” Beach
Silicon Valley, plus, doesn’t meet criteria #2
Lassen
Fresno LOL
Sacramento ROFL

 Possibly, but connotation may be wrong:

Malibu - first three seem too fancy
Napa
Sonoma
Cupertino - too self-promoting
Ventura - at least to Californians, this might sound low rent

 Possible Bets - vaguely in order

Mojave
Capistrano
Shasta
Calistoga
Sequoia
Point Reyes
Ojai - technically a town, but also a very natural area
a beach name without including “Beach” e.g. Hermosa
Pinnacles
Red Rock
Humboldt
Big Sur
Tahoe
Monterey
Carmel

I may add to this over time.

Continue reading →


Apple Watch Crown Events – Thinking About Discretely Triggered Events

One of the biggest frustration points for me on Apple Watch when working out is that a wet screen does not recognize touches very well. So a workout app that lets me mark a lap, pause the workout, or anything like that is limited, because many times it fails because I sweat a lot 1.

But now, with Apple exposing WKCrownSequencer and its delegate means that apps can receive direct input from the crown. Examples shown include rolling the crown and moving a marker along a plot.

But how does this help for discrete events? It is fairly trivial to create discrete events by triggering something based on a threshold rotationalDelta. Below is the code (not Swift, sorry!) for a quick proof of concept for marking laps by quickly spinning up, and stopping the timer by quickly spinning down.

I’ve only tested on my simulator so far, but when I test on the watch, I’ll try to capture video.

I would

Continue reading →


There Are A Lot Of Dudes

Every so often, you have a moment when you briefly see something in an entirely new light, and last night I had such a moment.

While cramming into a room for a great panel discussion about some of the Apple announcements, I was just overwhelmed by profound homogeneity of the programming community (sloppily dressed, male, white and asian). This is something I already knew, have talked about, and thought about. But in the moment, I just realized how intimidating at a visceral level it must be at times to enter this profession for anyone that isn’t in the demographic.

And all things considered, this was a SUPER welcoming event, with a panel that was half women, half men, the moderator also introduced the event with fully articulated and affirmed code of conduct. Really friendly. No “bad” behavior present at all.

I don’t have a point, but wow, when you get a few thousand programmers

Continue reading →


Swift: map vs. flatMap For Dummies

 tl;dr Summary

This is me, figuring out how map and flatMap work in Swift.

 tl;dr Conclusions:

  1. Think of optionals as an array that can hold 1 or 0 items.
  2. Arrays and optionals are both containers that can have map or flatMap applied
  3. map unwraps a container, transforms value with supplied function and rewraps result.
  4. flatMap unwraps a container, transforms value with supplied function and rewraps either a raw value, or the non-nil value of a contained result1

 Complete Version With Complete Examples

Recently, I had an issue where I was using a tableView with multiple selection allowed, and I had a short array with names ([String]), and I wanted a map function that would return the index of that name in a larger array with all the possible names.

smallNameArray.map({ largeNameArray.indexOf($0)! })

However, .indexOf() returns an optional value, and Swift won’t let map return nil

Continue reading →


Short  Watch Thoughts - IV Better Interaction - Focus Engine?

 Great, But Limited physical UX design

One of my favorite things about the design of the  Watch was the digital crown. It was a perfect translation of traditional watch interaction for a digital watch with scrolling and push interactions available. The addition of the second button was also very tastefully done and together they make a great palette for UX.

However, as others have noted, there are a couple of ways in which the ability to control the Apple watch is limited.

First, when the watch is wet, most touch interactions, including 3D touch, go out the window. This is very unfortunate when I am exercising. Otherwise I love running with the watch despite most exercise apps limitations.

Second, pressing the digital crown works quite reliably as the “home” button for the watch but often feels underutilized when I get the the app home screen.

Third, the primary action of the

Continue reading →