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.

Learning Elixir: Part 3

Hi All, Wow, we're already at part 3 and we're barely scratching the surface. I see a long road ahead with so much more learning to do. On the more positive side; I'm getting it and I'm finding it quite enjoyable so far... so let's crack on, shall we?

In the last few days I did two more experiments to do some basic sending and receiving between erlang processes (which I've come to find is a term which is interchangeable with BEAM processes, which is what I really mean).

My first task was to build a function (based on the video I linked to in part 1) that did some distributed work. So for this, I declared a function that took a list and a function and then the function would be applied to each item in the list. This was somewhat similar to a map() function in functional programming. Here's the Elixir part, each function would be run inside it's own Erlang process. Neato.

https://gist.github.com/samjarman/de7dd2337b425d1499cce16d0f1a5831

So, walking through the code, first we make a reference to the process by calling it me. Then on the list, we then map over the list, creating a function that spawns a process, which inside that sends back to the parent process a PID (self) and the result of applying the function to the element. Then on that list of PIDs we receive the result, and presto-we have a list of results. Pretty neat. With the task above, what wouldn't work is if the process was more complex (say, not multiplying a number by itself) and the process was to error out, nothing would rescue that... so that leads me to my next task.

My second task was to start playing with the concept of supervision, a reasonably crucial one in Elixir. I wanted to implement from scratch a really simple supervisor that would look at a randomly failing process and make sure it stayed alive.

https://gist.github.com/samjarman/7043ac55e9518969c8c1839d670d9622

So what I've done here is declared a worker function which fails just a little bit of the time, and if it does, it'll tell it's master about it before exiting. If the master hears about this, it'll respawn it and start listening all over again. Take a read through the code.

My next task is to start implementing some proper Elixir projects. There are also a few good ones to contribute to out there. If you have any suggestions for projects... I'm all ears!

Have you also been learning Elixir or Erlang too? Do you have any tips or comments? I’d love to hear them and share them in an upcoming post. Ping me on twitter.

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 that. static1.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!