Tag Archives: code snippet

Mistakes Were Made: Audio and ARC

There’s a mistake I have, to my own great embarrassment, made twice, so I think it’s worth writing up for posterity. This one’s brief: you can laugh at me and move on. Under ARC, AVAudioPlayers don’t retain themselves while playing. … Continue reading

Posted in Explanation | Tagged , , , , , , , | Leave a comment

Premature Completion: An Embarrassing Problem

Working on a project recently, Jerry and I came across an odd bug. We have a two-level UI that allows the user to navigate between several different scroll views. For the sake of keeping things pretty, we want to reset … Continue reading

Posted in Explanation | Tagged , , , , , , , , | 10 Comments

Countries of the World in an NSArray

Continuing our popular series of lists we’ve typed in so you don’t have to (although this one is thanks to sed). Caveats: scraped from a random source on the internet; may not be accurate; provided for entertainment/lorem ipsum purposes only. … Continue reading

Posted in Code | Tagged , , , , , , , | 1 Comment

Cancel dispatch_after

Joel and I have been working on a project recently that relies pretty heavily on the delayed execution of blocks. It became evident pretty quickly that we needed a way to cancel these blocks. We worked around the problem in … Continue reading

Posted in Code | Tagged , , , | 4 Comments

Mistakes Were Made: Integral Bounds

Here’s another mistake from the day job. (Why do they pay us? Because we do eventually find and correct our errors?) “Misaligned” CATextLayers As you may know, the Core Animation instrument has a flag to “Color Misaligned Images“. This is … Continue reading

Posted in Code | Tagged , , , , , , , , | Leave a comment

Quick Tip: Drawing Right Side Up With Core Text

Anyone who has decided to explore using Core Text on iOS has probably noticed that everything is drawn upside down. This is because Core Graphics contexts that have been created with functions provided by UIKit (such as UIGraphicsBeginImageContext, or the … Continue reading

Posted in Code | Tagged , , | 3 Comments

Localizing Arbitrary Strings the Scripty Way

I bet you saw my post about localizing US states and said to yourself, “Ha! That little sed script won’t do much for arbitrary strings!” You’re a jerk, but yes, you’re right. Before I give it away, does anyone see … Continue reading

Posted in Code | Tagged , , | Leave a comment

Localizing your US States array

Suppose you have a whiny co-worker who insists that all user-facing strings be localized. That’s what scripting tools are for, right? Specifically sed, in this case. sed ‘s/@”[^”]*”/NSLocalizedString(&, nil)/g’ This little script will match NSStrings and replace them with a … Continue reading

Posted in Code | Tagged , , , , | Leave a comment

US States in an NSArray

Save yourself a little typing time, take advantage of mine. [NSArray arrayWithObjects:@”Alabama”, @”Alaska”, @”Arizona”, @”Arkansas”, @”California”, @”Colorado”, @”Connecticut”, @”Delaware”, @”Florida”, @”Georgia”, @”Hawaii”, @”Idaho”, @”Illinois”, @”Indiana”, @”Iowa”, @”Kansas”, @”Kentucky”, @”Louisiana”, @”Maine”, @”Maryland”, @”Massachusetts”, @”Michigan”, @”Minnesota”, @”Mississippi”, @”Missouri”, @”Montana”, @”Nebraska”, @”Nevada”, @”New … Continue reading

Posted in Code | Tagged , , | 15 Comments