Skip to content

Archive for


Automatic Build Numbers for iOS Apps Using Xcode

UPDATE Sep 2014: Added another idea from Jared Sinclair, who has example code for Git.
UPDATE Jan 2013: Now also updating the build version in the dSYM file.

There are many articles that discuss how to automate build numbers in Xcode. However, some are misleading for iOS apps. Many are quite long. I wanted to find a short, simple way to do this.


On the target Summary tab your project settings, Xcode lets you set a Version and a Build. The version is what we are all familiar with, such as 5.0 and 5.1.1. The build is what often appears in parentheses after the version, as in 5.0 (134) and 5.1.1 (147).

Apple doesn’t seem to care what you use for Version (aka CFBundleShortVersionString), but Build (aka CFBundleVersion) must be a monotonically increasing string, comprised of one or more period-separated integers. Thus Apple will reject your update if you go from 1.1 (10) to 1.2 (0). The version is ignored and, alas, zero is clearly less than ten.

The part about integers is important too because Apple will also reject your update if you go from 1.01 (1.01) to 1.1 (1.1). The period is not a decimal place. Both (1.01) and (1.1) are interpreted as “the integer one followed by the integer one”. We saw this logic in action when OS X went from version 10.4.9 to 10.4.10.


If you do this wrong, you’ll see this error when you upload your app update:

This bundle is invalid. The key CFBundleVersion in the Info.plist file must contain a higher version than that of the previously uploaded version.

To get your monotonically increasing period-separated integer build number, you could just use the app version, like 5.1.1 (5.1.1). But I think it’s better to use a build number that can help identify the code from which that version of your app was built. Both Git and Mercurial include the ability to count commits, which is perfect—always increasing and helpful in identifying the code.

If you modify the Info.plist file in your project folder during the build process, you’ll probably need to commit the change to your code repository. This extra commit, while not harmful, is unnecessary. Instead, you can modify the Info.plist file in the app package after the build process is finished. The file will be in a binary format, but the PListBuddy tool can handle it.


Here is the script you need for Mercurial. This script also adds the bundle version to the dSYM file, which is necessary for correctly symbolicating your crash logs. It’s also required for several distribution mechanisms including TestFlight and HockeyApp.

ver = `/usr/local/bin/hg id -n`.strip
puts "Build number is #{ver}"
puts "Updating #{filepath}"
`/usr/libexec/PlistBuddy -c "Set :CFBundleVersion #{ver}" "#{filepath}"`
filepath = "#{ENV['DWARF_DSYM_FOLDER_PATH']}/#{ENV['DWARF_DSYM_FILE_NAME']}/Contents/Info.plist"
puts "Updating dSYM at #{filepath}"
`/usr/libexec/PlistBuddy -c "Set :CFBundleVersion #{ver}" "#{filepath}"`

The first line counts the number of commits in your local repository. It’s safe to use as long as your builds are done on the same machine. Repositories on other computers may have different commit counts. For Git, you can count your commits using a similar command.


  1. Select your project in the Project Navigator
  2. Select your target
  3. Select the Build Phases tab
  4. Choose “Add Build Phase”
  5. Select “Add Run Script”
  6. Change the Shell to “/usr/bin/ruby”
  7. Copy and paste the script

Within your app, you can grab the version and build number with this code:

NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [NSString stringWithFormat:@"%@ (%@)", appInfo[@"CFBundleShortVersionString"], appInfo[@"CFBundleVersion"]];

This will give you a string like 2.2 (134) that you can display in your app. I’m using the new object subscripting syntax in Objective-C, but it’s not too hard to switch back to using objectForKey:.

Follow Up

Jared Sinclair has a nice example of how to do this with Git. I really like the idea of using the branch name as a build suffix for Debug builds. I’m going to update my code to match.


Information on the Internet Lives Forever

I bought a mattress a while back and a bad experience with one of the products I purchased. The company handled the return much more gracefully that I was expecting. As I wrote up my experiences with the whole mattress buying experience, I mentioned my mixed experience and moved on. I didn’t think much more about it.

Until the owner of the store called me. We were both a little tense. I was worried about threats and lawsuits, and he was worried I’d be a jerk. He was losing some business from people who’d read my article. Yay for blogger justice! But his concern was correct because information lives forever on the Internet.

He could have fixed the problem, or switched to a new supplier, or discontinued that product, or even gone out of business, and my article would remain. I’m glad he called. He was nice, and I’m glad to have the opportunity to keep my article current.

Information on the Internet lives forever. Unless you want to find something cool you know you read several years ago, of course. Then it’s probably gone forever. I just try to keep up.


My Best Stuff

You may have noticed the new My Best Stuff section on the side. The articles there either continue to be the most viewed or have generated the best reaction from people who know me. I didn’t think much about it when I was calling it Popular or Recently Popular. Calling it “my best” makes me nervous.

It made me realize that those articles probably do represent my best writings, or at least my most successful. And I wonder if they’re actually any good. No real way to find out, except by forging ahead anyway.

So please don’t hesitate to let me know if I’m wrong about what to include in the list or if you have any comments or suggestions. You can follow me on Twitter here or email me .

I’ll update the list on occasion as I discover which articles resonate with people the best.


My Current Project

A few months ago, two friends asked if I’d be interested in working on a book project with them. Jed is a successful artist and illustrator. Noelle is a brilliant writer and educational designer. They’ve worked together on several projects and wanted a programmer to help design a book app. I said yes before they stopped talking. :)

Here is one of Jed’s early designs:

Story app mock up

It’s an interactive fiction fantasy story app, except that the plot is cohesive and targeted at a young adult audience. In many choosable path books, the endings were often very different from each other. For example, the plot might change from bank robbers to aliens depending on which door you went through. Also you died a lot.

In our story app, you nudge the main character in the direction you want her to go even as the story unfolds around her. The book remembers the choices you make and adjusts the text and artwork as you go along. Noelle is writing the same story more than 20 times and loving it. She’s been planning this story since high school.

A website is coming soon. We’re close to finishing the programming, art and writing for chapter one. Noelle is wrapping up chapter two in a few weeks.

Jed recently completed a successful Kickstarter project for traditional hand-made Japanese woodblock prints of video game characters. It’s kinda cool, so check it out if you’re interested.


3 Tips on Auto Synthesized Properties

Ha ha! You fool! You fell victim to one of the classic blunders, the most famous of which is “never get involved in a land war in Asia.” But only slightly less well-known is this: “Never have an auto-synthesized property and an instance variable with the same name when death is on the line!”


At work, my team decided to drop support for iOS 4. Most of our customers have upgraded to iOS 5.1. Surprisingly, very few are still using iOS 5.0. I guess over-the-air upgrades are working really well for people.

Our app is old. In some places we still checked if the user had upgraded to iOS 3 yet. :) My team spent the week on cleanup and paying down technical debt. My job was to:

  1. Convert to using object literals for arrays, dictionaries and numbers.
  2. Remove @synthesize calls.
  3. Switch all of our instance variables to properties.

I love shortening and removing code without losing functionality. The first two tasks went fairly quickly. But I…uh…learned a lot while tackling number three.

You can declare an instance variable in an @interface block — either the public interface in the .h file or the private interface in the .m file. You can also declare one in the @implementation block in the .m file. Or all three at once.

You can mix instance variables, properties and auto-synthesized properties. But auto-synthesized properties are so much nicer: less code, less maintenance, less boilerplate typing. Here are 3 tips to help you use properties more effectively.

1. Deal With Read-Only Properties

An auto-synthesized property generates an instance variable with the same name as the property except prefixed with an underscore. This is great because it’s clear whether you’re using the property (self.myprop) or the instance variable (_myprop). Using the bare name (myprop) doesn’t even compile, so you limit the confusion and bugs caused by accidental mistypes.

Auto-synthesized properties create their own getter and setter methods (avoiding some unnecessary typing). You can implement your own getter and/or setter, in which case those methods are not automatically generated. The instance variable (_myprop) is still synthesized.

However, if your property is readonly AND you implement your own getter method, then an instance variable is not synthesized. I suspect this is to allow for a named property that is dynamically calculated. In any case, if you would like an instance variable, you can force it to be synthesized by either:

  1. Using @synthesize myprop = _myprop; in your @implementation, or
  2. Redeclaring the property as readwrite in your private @interface

The second option works like inheritance in that you can redeclare a property as less-restrictive but not the other way. Redeclaring a public readwrite property as privately readonly isn’t possible, though why you’d want to do that remains a mystery.

2. Avoid Instance Variables

It is a Bad Thing™ to have both an auto-synthesized property and an instance variable declared with the same name.

  1. self.myprop = 1 uses the auto-synthesized instance variable
  2. myprop = 1 uses the declared instance variable
  3. _myprop = 1 uses the auto-synthesized instance variable

Since you end up with two instance variables, when you probably intended to have only one, doing this can cause lots of unexpected bugs and problems. Better to avoid declaring instance variables for your synthesized properties.

It is a Worse Thing™ to have two auto-synthesized properties of the same name with one prefixed with an underscore.

    @property myprop;
    @property _myprop;

This causes problems because self._myprop is different than _myprop when you really should have used __myprop, making you start to wonder about your own sanity. This doesn’t seem like it would happen much, but it can if you are importing several .h files, one of which uses underscores in its property names.

So don’t do that. :)

3. Use Instance Variables Correctly

In most cases, it’s best to stick with using the property (self.myprop) in your code. However, it’s important to use the instance variable (_myprop) in two cases:

  1. In your init: methods to avoid possible side-effects if you implement your own setter later, and
  2. In your custom getter and setter methods to avoid infinite recursion (always nice).

Auto-synthesized properties are great. Not quite as awesome as ARC, but close.


Bacon Candy

Picture of finished bacon candy

A delicious recipe for bacon candy from my friend Randy Hall:

  • 1 pound thick-cut bacon
  • 1 cup brown sugar
  • 1 teaspoon cayenne (optional)
  • 2 teaspoons favorite BBQ dry rub (optional)

Preheat the oven to 375 degrees. Mix brown sugar, cayenne, and BBQ rub together in a medium bowl. Place sugar mixture a gallon Ziploc bag. Add bacon and toss. Line a baking sheet with foil, and place a wire rack in the baking sheet. Lay the strips of bacon on the rack. Pat any remaining sugar mixture on the bacon. Put the baking sheet on the top rack of the oven and bake until crisp, about 20-25 minutes, turning once halfway through (re-coat with any additional sugar when turning if you want even more candy coating). When the bacon reaches desired crispiness, remove from the oven to a serving dish and let cool slightly before serving.

It’s a super simple recipe. The only real gotcha is finding the fine line between nice crispy bacon and black burnt sugary mess. Check it often at the end. It is delicious.


Are You Buying A Mattress?

UPDATED 15 Mar 2017

Buying a mattress is a terrible experience. A mattress is something we buy only rarely. So each time we head out shopping, we’re unfamiliar with the current trends in mattress technology, comfort and safety. Like many other manufacturers, mattress makers often try to save money by using low quality materials or construction methods, especially on the inside where it’s hard to see. A month ago, my wife and I bought a bigger bed and needed to replace our mattress. Here is what I discovered.

Mattresses are often made from materials that can be politely described only as unnatural. Over time, they can break down, wear out, give off potentially harmful gasses and quickly become uncomfortable. If you have allergies or are sensitive to smells, noises or motion transfer, buying the wrong mattress could lead to years of difficulty getting a good night’s rest.

Mattress Type

I spent way too much time reading, searching and researching on the Internet. I ruled out foam because of off-gassing, odor and durability. Innerspring mattresses are bad at preventing motion transfer, even the ones with separately wrapped coils (which is what we’ve been sleeping on for the last few years). While there are many mattress that use a combination of materials, a solid latex mattress seems like the best option.

Latex is the tree sap from which rubber is made. A latex mattress is made from natural rubber foam molded into shape using one of two processes: dunlop or talalay (see here also). Dunlop is older, while Talalay produces a slightly finer and more even foam. Synthetic latex is also used in mattresses. A “blended” latex mattress is a mix of natural and synthetic latex. If you have a latex allergy, you’ll want a synthetic mattress. If not, natural latex seems to last longer.


Latex mattresses are most often composed of several layers of latex stacked on top of one other, encased in a cover. Latex layers (and toppers) are made by only a few large corporations. You can ask the manufacturer where they get their latex. Latex International seems to be highly regarded.

Latex layers have different levels of firmness measured in ILD (Indentation Load Deflection). Soft latex typically has an ILD of 20-25, while firm latex might be 35-40. The most common arrangement seems to be 3″ of firm latex on the bottom, 3″ of medium latex in the middle and 3″ of soft latex on the top. Another common option is 6″ of firm on the bottom with 2″ of medium or soft on top. Having several 3″ layers with differing firmness gives you the flexibility to rearrange them if desired. For example, moving the soft layer to the middle and putting the medium layer on top gives the mattress a firmer feel without requiring another purchase.


Most covers (also called ticking) for a latex mattress will have a zipper so you can swap layers or stack them in a different order. The best covers are made from quilted cotton with wool padding. The quilting keeps the padding from bunching up over time.

By law, mattress cover padding must be resistant to fire. Wool is naturally fire-resistant. Other materials, like polyester, must be chemically treated to provide resistance. If you’re going the latex route, especially for health or environmental reasons, it seems best to avoid chemically treated synthetic material in your mattress, all of which can off-gas.


Getting a mattress pad is important to protect the mattress from spills because latex and most mattress covers are not machine washable. Any pad labeled “waterproof” is going to have a layer of vinyl or plastic, or use a thin coating of polyethylene or polyurethane. Water-resistant pads are available in cotton, cotton-and-polyester and cotton-and-wool varieties. Pads range from 1/4″ to 1.5″ thick.


Latex and other foam mattresses do not require box springs. Instead, if extra height is needed, use a mattress foundation. A foundation is basically a wooden box covered by fabric that does not have springs. They vary from 4″ to 10″ in height. Most foundations have wooden slats on top. The gap between slats ranges from 2″ (very good) to 5″ (less so). Too much space between slats allows the mattress to sag and decreases back support and the lifetime of the mattress. The covers for many self-assembled foundations use a drawstring and are open on the bottom.

If you have a box spring that you’d like to continue using, you can put plywood (or something similar) on top to help improve support and stability.


Buying high-quality cotton sheets seems easy. The best sheets are woven from single-ply thread made from Supima™ or Egyptian cotton. Thread counts in the range 400-800 are great. Any higher and the sheets start to feel flimsy because of how thin the thread has to be.

Sadly, there have been many cases of manufacturers lying about thread counts or using fabric incorrectly labeled as Egyptian. And make sure your sheets say “100%” or else they may not be. A good return policy is your best defense.

Where To Buy Online

If you are shopping online, there are many places to buy a latex mattress. You can even buy latex layers and a cover separately as a money-saving DIY project. What’s The Best Mattress is a good place to do research. There is a great list of places to start shopping. I looked at PlushBeds, Rocky Mountain Mattress, SleepEZ, Foam By Mail, Foam Sweet Foam, Tranquility Mattress and The Natural Bed Store. Be sure to check the return policies because shipping costs, restocking fees, return periods and warranties all vary.

Interestingly, nearly all of the foundations I found online were re-branded versions of this one. Look for that image as you’re shopping. Alternatives include one by U.S. Box Spring and another by Bed In A Box, which is manufactured by KD Frames. Any foundation from a local store will work too. If you buy locally, you can probably have your old mattress taken away for free.

Here’s What I Did

I decided on a DIY project. I ordered a cotton-and-wool cover and three latex layers from mattresses247 on eBay: one soft, one medium, one firm. Their latex layers are blended “factory seconds” which are new, but have cosmetic defects — like lumpy M&Ms that can’t be sold at retail. The defects are visible, but do not seem to affect the feel of the mattress at all. And saving $1,000 is pretty nice. They have great return policy (30 days, no restocking fees, only pay return shipping). Valerie was responsive and very helpful over email.

I bought the American Hardwood Mattress Foundation from BedInABox. It’s extremely well made and perfectly quiet. The cover is open on the bottom and made from polyester and cotton, which was a little disappointing at first. Polyester doesn’t off-gas much, and I can buy another cover later if I want. The slats have a 3.5″ gap, which seems a little wide considering the price. I nailed using some thin sheets of hard material on top of the slats to try to avoid sagging. But while looking underneath later on, it didn’t seem like the mattress was sinking into the remaining gaps much.

UPDATE Oct 10, 2012: Scott Ravenhorst, owner of Foam Sweet Foam, reached out to me about my experience. I’ve updated my comments here to reflect that.

I ordered my first mattress pad from Foam Sweet Foam. I really liked the quality and construction, but ended up returning it. Foam Sweet Foam has a great return policy and gladly took it back despite the fact I had washed it twice. The owner later read my article and called me about my experience. He confirmed I’d gotten a defective pad and that nearly all of their customers are very happy. If I hadn’t already found an alternative, I would have given them another shot. Foam Sweet Foam takes good care of their customers, which isn’t something that is common on the Internet.

My second pad is a Washable Wool-Filled Fitted Mattress Pad by Natura World from Amazon. I confirmed with Natura that the “Wash N Snuggle” fitted pad is the same product as the “Washable Wool-Filled” fitted pad. We’ve been sleeping on it for a week four months, and I really like it. We aired it out for a day, washed it once, and can’t smell anything.

I ordered two sets of sheets from Costco. They have a great reputation and return policy. While I liked the Charisma Egyptian cotton sheets, I ended up keeping the Kirkland Supima sheets. They are really soft, seem durable and feel great.


Overall, I’m very happy with my new mattress: latex, hardwood foundation, cotton-and-wool cover and pad, high-quality cotton sheets. It’s true that it takes a while to get used to a new mattress, and it’s only been a week. But I find myself looking forward to laying down at night. It’s too soon to say if I’m sleeping better, but I definitely find myself smiling more.

2 Years Later

It’s been over two years since we purchased our mattress. I thought I’d add a quick footnote on how things are going.

We are still sleeping on our mattress, and it’s held up pretty well. The mattress is sagging a little where we sleep, though not in the middle, and it doesn’t seem to be getting any worse. It’s still really comfortable. My parents house-sat one night and told me later that they thought it was really comfortable.

If I had it to do over again, I would probably not buy my latex on eBay. It wasn’t made by Latex International, and I wonder if that is why it’s not wearing as well as I’d hoped. And if there had been a problem, it would’ve been nearly impossible to return because the latex expands and no longer fits in the box.

The sheets wore out a few months ago, and we’ve replaced them. We sit on our bed a lot at night, and they tore where I sit. They’d gotten pretty thin. The new ones are not as comfortable, but seem sturdier. I’m not sure if I prefer comfort or durability. Next time, I’m going to try to find both. :)

Everything else seems as good as new. My wife sleeps very lightly, often waking up when the kids talk in their sleep. I don’t wake her up at nights on this mattress, which is great. No smells, not much movement, very comfortable.

5 Years Later

Our mattress is starting to sag some. We sometimes fight over the middle. :) However, after a recent trip staying in hotels, we couldn’t wait to get home to our (still) much nicer mattress. When it starts to bother us, I’m planning to just buy replacement latex (or perhaps a full mattress).


200 Million iPads Update

UPDATE 2012-04-24: My March estimate of 11.8 million was accurate. I’ve added a link below and updated the image to reflect the change.

UPDATE 2012-08-01: My July estimate of 23.3 million was way off. Like Asymco says, “It’s perhaps unrealistic to expect 150% growth for more than one year.”

Back in September, I estimated that Apple would sell 200 million iPads by the end of 2012. It looks like I was a little too optimistic.

Apple just reported stellar quarterly results. However, iPad sales growth was not quite as strong as Apple’s initial sales seemed to indicate. Two years after introduction, the iPad is selling better than the iPhone did two years after its debut. But it looks like it may take one extra quarter for Apple to hit 200 million iPads.

Actual Results

Estimated iPad sales through 2012

Estimated Results

  • Jan to Mar 2012: 11.8 million (this was accurate)
  • Apr to Jun 2012: 23.3 million (actual amount was 17.0 million)
  • Jul to Sep 2012: 28.0 million
  • Oct to Dec 2012: 38.9 million
  • Jan to Mar 2013: 29.8 million (was 29.9 due to rounding differences)

Disclosure: I own AAPL stock.


The First 100 Days of a Startup

Josh Coates, founder of Mozy and current CEO of Instructure, once taught a series of classes at BYU on high-tech startups. I jumped at the chance to audit his class.

One of the things Josh covered was what should happen during the first 100 days (14 weeks) of a high-tech startup.

Week 1 — Research and choose business
Week 2 — Build financial model and development plan
Week 3 — Build pitch with screenshots and practice
Week 4 — Interview law firm, staff and advisers
Week 5 — Incorporate and setup shop with office space and equipment
Week 6 — Initial documents, books, hires and cap table
Week 7 — Create website and logo (do a trademark search)
Week 8 — Identify 10 to 20 potential investors and study who else they invest in
Week 9 — Practice the pitch and setup meeting with the least important investor
Week 10 — Interview, build product, pitch again
Week 11 — Interview, build product, pitch again
Week 12 — Interview, build product, pitch again
Week 13 — Interview, build product, pitch again
Week 14 — Interview, build product, pitch again

He recommended interviewing one potential employee every day. Pitching to the least important investor first lets you have a chance to practice in a situation where making a mistake isn’t as damaging.

I first met Josh just after publication of an article he wrote on how many angel investors in Utah were doing it wrong. The article, entitled “Poison in the Well”, in addition to having a great title, was direct and clear in its criticism. It was one of the reasons I later applied to work at Mozy.

For anyone who knows him, I think “direct and clear criticism” is a good phrase to describe what it’s like to work for Josh. His class was no exception. It was a great chance to learn from someone who’s been there and done it successfully.