Style Checking for iOS Development

In a recent episode of Silicon Valley, Richard and Winnie had a fight about Spaces vs Tabs. It reminded me of this comic on the debate: TabsSpacesBoth

Obviously the point of the comic is that the decision is fairly arbitrary, but consistency is of the utmost important.

So the question is: Teams how do you stay consistent? or How do you stay consistent to your former self? The answer: Style Checking.

So I thought I'd write this blog post to talk about the way I use style checking. Obviously I spend a lot of time doing iOS, so let's talk about that.

Firstly, I have a few requirements for such as tool.

  1. Support both Swift and Objective-C
  2. Produce inline style errors in Xcode
  3. Easy to configure
  4. A nice settings file that could be checked into Git
  5. Free or low cost

What I found about 2 years ago was Objective-Clean (and later, it's sister product Swift-Clean). These are fantastic tools created The Ostlers and have served my needs since.

Objective-Clean icon

Swfic Clean icon

The workflow is really simple too. To start, simply gather your team and take the survey together. Once the yelling ceases and the evil eyes have stopped being made, you'll have yourself a downloadable settings file.

Once you've got that, grab a copy of the software (It's very cheap at $10USD).

Then, open the app, drag your xcodeproject or xcworkspace into it, and it'll configure itself. Under the hood, it adds a build step that'll style check your code after each build.

From there, the style errors will jump out at you, and you can take a small amount of time to bring your project up to consistency. Boom.

So that's how I take care of Style Checking. Props to Blair for showing me the ways back in the day. It's been rewarding to keep our code looking 💯.


Do you use style checking? If so, what do you use? Do you know any other tools? I'd love to hear from you on twitter - I'm @samjarman.

Confusing Topics in iOS Development

Hi All, I thought it'd make an interesting post (hopefully?!) to talk about the stuff that still, after about seven years of tinkering with iOS to talk about the stuff that still confuses me sometimes, or things I always have to look up.

type-away-numero-dos

Bounds vs Frame

Like, wow... this always gets me. I generally work at a higher level of abstraction, but usually when I come to this I have to google it again and again. Frame is relative to superview, bounds to itself. Use frame or center for positioning and bounds for doing stuff inside the view, such as cropping.

Objective-C Block Syntax

Obviously. Side note: I was gonna link to Fucking Block Syntax but now I see it's Fucking Swift Block Syntax.

Compression Resistance vs Content Hugging

Let's be honest, AutoLayout has a hell of a learning curve, and by not touching UI much, I sometimes miss things with my spare time tinkering. I usually look up the below photo from @mokagio to remember. Also here's a good post on thatstatic1.squarespace

Setting  Text on a UILabel

Lol, like almost every time I do myLabel = @"foo"; rather than myLabel.text = @"foo"; Just one of those dumb things I can't seem to shake!

Logging a String

My brain is weird sometimes. I feel like my brain thinks "one day I'll be able to log an instance of NSString directly" so now and again I check. Nope.

NSLog(@"%@", myString); not NSLog(myString);

Of course, I know why it takes a string formatter argument rather than a string directly, but it still seems annoying to me. As I type this, I realise this could be "fixed" with a Macro?

Ex-Confusions

There are a few things I used to get confused about but then suddenly don't.

AutoLayout

When I first started learning AutoLayout, I was probably overthinking it or had the wrong mental model of how it worked.

The trick for me: Remember - two constraints, x pos and width, and y-pos and height. Satisfy those and you should be good to start with!

Dates and Times

Date and Time manipulation, formatting and timezones were always super confusing. My previous experience with these was with the C# DateTime library which worked a whole lot differently so it took me a while to get in the spirit of the Apple NSDate thinking.

The trick for me: Remember an NSDate is just an integer of seconds from 1970. The rest (timezone, format, components) is display.

Provisioning

I feel you were waiting for me to write this. People love to hate on provisioning but it's really not that hard? However, It can just break in so many ways and get frustrating. Just don't use the Fix Issues button (for now).

The trick for me: Taking the time to learn the parts. Signing Keys, Certificate, Provisioning Profile, WDC Certificate, App ID etc, Entitlements.


So that's my short list ranging from serious to less serious. I hope you feel less bad about being stuck on some things now. Remember: Chin up, you're probably not the only one feeling dumb about this stuff. Just ask!

How about you? What do you find confusing about iOS or development? Tweet me!

Thanks for reading!

Apps are Making us Better People

A role of an actor is to capture the essence of the character they're trying to play. If you think of the trope of "actors trying to make it", you'll often see them showing their "range", which is a typically done with a series of photographs showing various emotional states. Typically, actors would work for years to get this right, developings these expressions in front of a the mirror. However, times have changed. Now everyone has a decently quality forward-facing camera in their pocket. And boy do we know it. As a society in recent years, we've been obsessed with that small camera. The one tiny technological change that will define a generation. "Selfies" are so commonplace, that even those quotes around the word were perhaps unnecessary. These photos of one's own expression, typically reacting to a situation are now so commonplace, even my parents are beginning to take them.

But it doesn't just stop with the camera app built into your smartphone. Snapchat, an app that's come almost out of nowhere (since ~2014) promoted selfies and reactions that can be read in a small timeframe. The metric for a great snapchat is being able to understand it fully before the timer runs out. It's not just Snapchat, one could argue Vine and YouTube did this as well. Another great example is Musical.ly, an app for recording yourself lip syncing – How is it we can convey so much with just a silent movement of our lips?

I believe a generation of kids and young adults are now training themselves in the fine art of expression. Expression is a cornerstone of society, a way to tell someone what you're feeling without saying a single word. It's so deeply important for interpersonal communication and relationships, but often overlooked by its inherent subtlety.  These are the very reasons why actors have to get it right – they have to be able to match society and play characters, down to the musty subtle of details.

Social apps are often bashed for pulling people apart with the common example coming to mind of a group of friends out for dinner, ignoring each other for the allure of an unread twitter feed. While that may be true to an extent, the video and picture messaging apps are having quite the opposite effect.

A generation is being trained to produce and better recognise expression. The consequence of this being that these people will be able to communicate better, feel more in sync and have more meaningful and deeper connections.

So next time you see a young person taking a selfie, don't smirk. Think. Be envious. That person will most likely relationships better than most of us can ever dream. And who knows, perhaps they'll win an Oscar one day.