Framed in an interview!

Recently I have been interviewing and it is eye opening to be the other side of the interview table/Zoom chat! Having been an iOS developer for 14+ years, I think there are things you learn very early on in your career that you never question or need to revisit it again and it can catch you a little off-guard. One of those areas that I got asked about recently was about the relationship between the frame, bounds and transforms in a `UIView`.

Continue reading

Beautifully-formatted Times and Numbers

Example of rendered proportional numbers and monospaced numbers

Example of rendered proportional numbers and monospaced numbers

Not all font instances are created equally! In iOS text is mostly displayed using proportional fonts, meaning each character width is trimmed and varies depending on each character. This makes the text easier to read and feel more natural and you’ll notice this on characters such as ‘i’ which will often be the thinnest character compared to say an ‘m’ character. However for numbers displayed in a tabular format such as times, figures and currencies you’ll want monospaced characters so you can tidy up the layout and visually scan the data quickly. So how do you do this?
Continue reading

Facebook’s London Mobile Forum 2.0

Scott Goodson of Facebook starting the discussions with developers

Scott Goodson of Facebook starting the discussions with developers in Hoxton, Shoreditch, London.

Last week I was fortunate to attend Facebook’s London Mobile Forum 2.0. This gathering of top London mobile developers and designers was a great chance to swap ideas and listen to a number of talks by Facebook, Big Nerd Ranch, Yammer, Bloom and Mozilla to name a few. The event was tiny with only 60 people in the room but it had many big players and it was great to talk to as many of them as possible, particularly at the free bar Facebook had laid on in the evening! So what mobile development secrets did we talk about? Continue reading

5 Time-saving Objective-C tips every developer should know

Batman Flat White Coffee

Here’s a quick fire list of 5 time-saving Objective-C tips that every developer should know. Perfect for making time for that extra coffee!

1. Enum shorthand

Enums at their simplest are labelled sets of integers. Where an inexperienced programmer might use a number to represent the download state of an image lets say, e.g. 0 = queued, 1 = downloading, 2 = downloaded, 3 = complete… When using these numbers in actual code a simple slip of the finger on the keyboard and they could easily type an extra digit in their if statement or assignment. These types of errors don’t usually show up when compiling. Even worse, these are usually obscure errors that only reveal themselves at run-time and only then when things don’t work as expected often requiring considerable debugging effort.

This is where enums step in. Enums are really handy and allow you to associate symbols or ‘labels’ with integers. If you type an enum value that doesn’t exist the compiler steps in and reports an error at compile-time instead and Xcode will probably suggest a fix for you if it was a typo! The other benefit of enums is that you can quickly add new values into them and assuming your code doesn’t save the integer to disk your code will automatically work with the new values.

There are a couple of different ways to define enums but the easiest way which will also provide Xcode with some extra compiling hints is as follows:

Continue reading

Core Animation stops animation on app relaunch

On one of my projects I discovered a bug in a never-ending animation I had set up. Whenever the app was suspended (such as when you multitask and open another app), on relaunching the app the animation was frozen. After some investigating, I discovered that with Core Animation you need to set a flag on the CABasicAnimation class called removedOnCompletion to NO otherwise the animation will get cleaned up when it gets suspended.

Objective-C:

CABasicAnimation *dartWiggleAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
dartWiggleAnimation.fromValue =
   [NSValue valueWithCGPoint:CGPointMake(self.center.x-DART_WIGGLE_HALF, self.center.y+DART_CENTER_H_OFFSET)];
dartWiggleAnimation.toValue =
   [NSValue valueWithCGPoint:CGPointMake(self.center.x+DART_WIGGLE_HALF, self.center.y+DART_CENTER_H_OFFSET)];
dartWiggleAnimation.timingFunction =
   [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; 
dartWiggleAnimation.duration = 0.4;
dartWiggleAnimation.repeatCount = HUGE_VALF;
dartWiggleAnimation.autoreverses = YES;
dartWiggleAnimation.removedOnCompletion = NO;
[[nextDart layer] addAnimation:dartWiggleAnimation forKey:@"dartWiggle"];

Swift:


        let dartWiggleAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.position))
        dartWiggleAnimation.fromValue = CGPoint(x: self.center.x - DART_WIGGLE_HALF, y: self.center.y + DART_CENTER_H_OFFSET)
        dartWiggleAnimation.toValue = CGPoint(x: self.center.x + DART_WIGGLE_HALF, y: self.center.y + DART_CENTER_H_OFFSET)
        dartWiggleAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        dartWiggleAnimation.duration = 0.4
        dartWiggleAnimation.repeatCount = Float.greatestFiniteMagnitude
        dartWiggleAnimation.autoreverses = true
        dartWiggleAnimation.isRemovedOnCompletion = false
        nextDart.layer.add(dartWiggleAnimation, forKey: "dartWiggle")

Does this seem like a bug or a feature?