Ben Dodson

Freelance iOS, macOS, Apple Watch, and Apple TV Developer

Xcode 6 Essentials

I’m happy to announce that a book I worked on as a technical reviewer is now available; Xcode 6 Essentials by Jayant Varma. The book works as a good overview of Xcode 6 and the Swift language and is suitable for both OS X and iOS developers. My role was to ensure technical accuracy and to make sure that all of the code samples work as expected.

Xcode 6 Essentials

You can get it now in both print and eBook formats from Packt Publishing.

SKProduct localized price in Swift

I’m currently working on a Swift project which uses In App Purchasing (IAP). One of the many pitfalls of IAP is displaying the cost of a product in the correct format; all too often developers use the default US formatting leading to apps showing prices of $0.99 in the UK. Gross!

You may think you can use the locale of the device to format the number and you’d be correct apart from the user may be using an App Store in a different locale to that of their device (i.e. a UK account but they have their device sent to French if that is their primary language). The SKProduct object that iTunes returns has a locale attached so it is fairly simple to format the price with that in order to get the localized version:

import StoreKit

extension SKProduct {
    func localizedPrice() -> String {
        let formatter = NSNumberFormatter()
        formatter.numberStyle = .CurrencyStyle
        formatter.locale = self.priceLocale
        return formatter.stringFromNumber(self.price)!

The above is a simple Swift extension (also available on GitHub) which, if it is in your project, will automatically be available on any SKProduct object (similar to using Categories in Objective-C). If we assume we have an SKProduct called product, we can now run:

NSLog("The price of this product is \(product.localizedPrice())")
// Example output: The price of this product is £0.99

It’s amazing how many apps either don’t display the price of an IAP in advance or display it in the wrong locale. Don’t let your app be one of them.

Update, July 2018: I’ve updated this script so that it is now an optional string property and written in Swift 4.

import StoreKit

extension SKProduct {
    var localizedPrice: String? {
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        formatter.locale = priceLocale
        return formatter.string(from: price)


Usage is much the same although it is no longer a function and you are responsible for unpacking the optional string:

NSLog("The price of this product is \(product.localizedPrice ?? "")")
// Example output: The price of this product is £0.99

Yosemite WiFi Workaround: Airport Express and USB Ethernet Adapter

Like many people, Yosemite has been a total killer for my WiFi. I finally broke down over the weekend when my WiFI was disconnecting every 10 seconds or so1. There is now a workaround available but it requires losing the ability to AirDrop which I use frequently. I’ve eventually fixed it with a long winded solution which I thought I’d share, but first a little backstory…

My WiFi is completely Apple-centric. I have an Airport Extreme (the newest 802.11ac model) and nothing but Apple computers. There are a couple of Apple TVs in the house and a few Airport Express’ for AirPlaying music. A little while ago I detailed how Yosemite was erroneously connecting through an Airport Express causing serious slowdown; the solution I had at that time was to separate my WiFi into 5GHz and 2.4GHz channels (with all AirPlay on 2.4 and all devices on 5). That was the setup.

Now, I’ve had to revert to doing this for my work computer:

Fixing Yosemite with an Airport Express and USB Ethernet cable

That’s right, I’ve had to plug in a USB Ethernet adapter and use a LAN cable to an Airport Express operating as a wireless bridge! As far as Yosemite is concerned, that’s a LAN connection and so it doesn’t drop out continuously. Problem solved!

There was one issue though; that Apple USB Ethernet adapter (which they still sell) doesn’t work in Mavericks yet alone Yosemite. To fix it, you need to download the drivers for the chip it is built on (helpfully available from ASIX), restart Yosemite, then manually add a USB Ethernet connection within Network in System Settings.

It’s all working like a charm, complete with full AirDrop support and no dropped connections. My new Retina iMac is coming today2 so I’m hoping that it having an 802.11ac chip will forgoe the need for this ridiculous workaround. At the very least I’ll be able to leave out the ethernet adapter!

  1. When I buy a house rather than rent, the first thing going in will be a gigabit LAN throughout. WiFi isn’t good enough for a media server and work machine. ↩︎

  2. “Out For Delivery”. Feels like I’ve been waiting forever! ↩︎

Dishwasher tablets and app competition

This week I bought some new dishwasher tablets online that happened to be on offer. When they arrived, their packaging had a banner at the top saying ‘switch & see the difference’ which got me thinking about app competition.

I noticed it today when I loaded the dishwasher after breakfast. Where I usually rinse the plates, I instead put them straight in so I could test if these tablets really were any better. When I unloaded the dishes and found them not as clean as usual, I immediately thought not to buy those tablets again. The strange thing about the above is that it was a totally subconcious decision both to forgo rinsing and to blame the new tablets rather than my change of habit.

This relates to app competition as it shows something which is hardwired in us; a competitor must be much better in order to affect a change. If your app is competing by having the same features or slightly more features, that might not be enough to make your competitors customers switch.

When I look at competitors for WallaBee, the main one is PackRat, a collecting game that runs on Facebook. Whilst we have better artwork and features, it is still a struggle to make people switch as there isn’t necessarily a killer reason for them to make that switch. That’s the task I’m focussing on now. I need to go that extra mile to get players to change to my game; I need to wash their non-rinsed plates.

Speeding up your DNS

Following on from my post last week about speeding up my home network, I noticed that my connection has still been quite slow when viewing websites. I have a steady 72Mbps down / 19Mbps up connection so that wasn’t the issue which narrowed it down to being either something wrong with my laptop or my DNS.

A little while ago, I found a great little app called namebench which searches through all kinds of DNS providers to find you the best speed. It was created by some Google engineers during their 20% time and works on OS X, Windows, and Linux. I usually use it as soon as I get a new machine but I’d forgotten to run it following my update to Yosemite which involved a fresh install. As it turns out, my home BT DNS is terrible and namebench managed to find some BT DNS servers that were 245% faster! Now my browser is flying along and it feels like I have a totally new connection.

I’d thoroughly recommend giving namebench a try - it’s totally free and takes around 15 minutes but you may end up with a much faster connection at the end of it.

Issues with Airport Express, Airport Extreme, and OS X Yosemite

I finally fixed a problem today that has been plaguing me for the past couple of weeks. For some reason, my MacBook Pro was getting a pitiful internet speed (around 1Mbps on an 80Mbps connection). Sometimes restarting my Airport Extreme router would fix the problem but it would slow down to a crawl a few minutes later. If I moved downstairs (near the router), then suddenly the speed would be much more acceptable.

After spending some time looking at my wireless network settings, I realised I was connecting to an 802.11n network. This is odd as I have a new 802.11ac Airport Extreme. It turns out the culprit was an Airport Express I put in my bedroom which I use purely for Airplay to a set of speakers. It is one of the newer models that supports 802.11n and it was joined to, but not extending, my wireless network from the Airport Extreme. For some reason, and I’m fairly sure it is a change in Yosemite, my MacBook was connecting to that Airport Express via the 802.11n despite the fact it wasn’t an extended network and it was obviously slower than the 802.11ac router which is only slightly further away. This slashed my connection speed by roughly 90% as everything was routed through the bridged connection.

The solution I’ve put in place was to give the 5GHz network a different name on my Airport Extreme. I’ve configured all of my Airport Express cards and Apple TVs to connect to the 2.4GHz network and all my regular devices connect to the 5GHz. There is now no danger of my MacBook accidentally connecting to an extended network but AirPlay still works like a dream.

If you notice you’ve got a slower connection since upgrading to Yosemite, it might be worth taking a look if any AirPlay devices are to blame!

October LEGO Updates

I’ve been meaning to write a couple of LEGO updates this month as there is so much cool stuff being unveiled. In the end I decided to do it as one big post…

Slave I

A video was released from the LEGO Design team showing off the latest UCS Star Wars set coming in January; Boba Fett’s iconic ship Slave I.

This looks like an absolutely fantastic set with a lot of cool features, the standard UCS stand, and (best of all) a Han Solo frozen in Carbonite!1 The Slave I is showing on the LEGO Website as being available on 1st Jan 2015 and consists of 1996 pieces. UCS sets like this are usually made available to VIP members a couple of weeks before but I’m not sure if that will happen with it being Christmas.

Speaking of Christmas…

Christmas LEGO

All of the LEGO Christmas sets are now available including Santa’s Workshop. Throughout October there are double points for VIP members and if you spend over £50 you get an exclusive Toy Workshop. I’m quite tempted by the workshop and a few baubles for the tree!

LEGO Santa's Workshop

The Hobbit

Today saw the release of 4 new sets in ‘The Hobbit’ series. These range from the small Witch-king Battle to the largest Hobbit set yet with The Lonely Mountain (complete with Smaug). As with the previous 5 sets, there is something about these I’m just not keen on. I loved the Lord of the Rings sets so much that I bought all of them but there’s something about The Hobbit which doesn’t grab me in the same way. The Lonely Mountain set is also very expensive (most likely to cover the cost of Smaug) at £99.99 for less than 900 pieces.

LEGO The Hobbit: The Lonely Mountain

Jurassic (Park) World

One of the more exciting announcements last week is that Universal have confirmed LEGO will be a licensing partner for Jurassic World, the new Jurassic Park movie due next year. When I collected the LEGO Dino series a few years ago, I thought it would be much better as a licensed Jurassic Park set and it seems that dream has come true. I’m hoping this will go hand in hand with a Jurassic Park LEGO game from Telltale with all 4 films. If the sets go down well, I’m fairly sure they’ll do some of the classic scenes from the original 3 films.

Blocks Magazine

Finally, Blocks magazine (which I’ve raved about before) becomes a monthly magazine starting next week. If you order an annual subscription, they’re sending out a really cool minifigure of the editor complete with a tiny pilot issue of the magazine. Mine arrived today and I can’t wait for the magazine to come next week!

Blocks Magazine Subscription Limited Edition Minifigure

That pretty much sums up the exciting LEGO announcements so far this month. My LEGO room still in the process of being setup after moving house and I have these sets to finish:

  1. This was originally in 9516 Jabba’s Palace and almost tempted me into buying that incredibly overpriced set (I’m glad I didn’t in the end) ↩︎

‘No results found’ on iTunes Artwork Finder

My iTunes Artwork Finder has proven very popular over the last couple of years. The issue with popularity is that the amount of correspondence increases. In the past two years, the top requests via email have been:

  1. Support for a specific country
  2. Asking for artwork of a specific show or film

I fixed the first a little while ago by automatically listing all of the iTunes countries but the second continues to be a constant issue in my inbox.

The way the finder works is to use the iTunes Search API to find the item you are interested in and then retrieve the artwork. This basically means that if the item isn’t on iTunes1, this tool won’t find the artwork for you. If you email me asking for a specific show or movie cover, I can’t help you.2

To try and limit the amount of email I get like this, I put in a disclaimer on the website. This got buried at the bottom of the page when I had a redesign so now I’ve added a note within the results.

"No results found" on iTunes Artwork Finder

Hopefully that should work!

  1. It might that a film hasn’t been released yet, the TV show is only on Netflix, or there is some other reason why iTunes doesn’t stock the film, show, or album you are looking for. ↩︎

  2. I will generally use Subler or Google Image Search if the iTunes Artwork Finder comes up blank. ↩︎

The problem with Allow Full Access on iOS 8 keyboards

I’ve never had a desire to change the stock keyboard on iOS. When the announcement was made at WWDC 2014, I thought that it was an interesting feature, but not one I would ever want to use. That changed when I saw the teaser page for PopKey, a keyboard that allowed you to paste animated GIFs straight into your conversations. That made me think about keyboards in a different way and how developers might create interesting keyboards that aren’t just improved ways of typing1.

As it turns out, PopKey isn’t very good. It doesn’t have search, watermarks the images, requires you to create an account and give over your phone number, and it was beaten by Riffsy which is actually better2.

Anyway, the problem I’ve seen over and over again is that these keyboards require “Full Access”. This is a feature that basically enables the keyboard to talk to its host app and to the internet. The reason you might want this for a keyboard is that it might do auto-correct (iOS 8 keyboards do not have access to the Apple auto-correct algorithms) and therefore does some processing in an app or in the cloud. With Riffsy and PopKey, this is obviously required in order that it can download the GIFs from the internet. The real issue isn’t that it requires this access, but that Apple puts up this message when you enable it:

Allow Full Access dialogue on iOS 8

“This could include sensitive information such as your credit card number or street address” - could they make that sound any scarier?

I’ve seen numerous people tweeting at PopKey asking them why it requires this access and how they won’t use the app until that requirement is turned off (which obviously won’t work - it needs internet access). I engaged a few in conversation and, even after I explained how it worked, the message I got back was “I don’t trust it”. I’ve even chatted to a few iOS developers who refuse to install a GIF keyboard because of that warning!

The basic problem is that the alert message you see is almost too scary and doesn’t give enough information. It was obviously written for what Apple expected; text keyboards. I’m not sure of a complete solution but as a start it needs to make it clearer that only things you type in that keyboard can be (potentially) seen by the developer. You don’t type anything in a GIF keyboard so the developers, if they are logging everything, can only see what stupid images you are sending. In addition, 3rd party apps can block custom keyboards from showing on sensitive screens (i.e. when entering your master password in 1Password or entering your pin in a banking app) and password fields automatically disable 3rd party apps (try it in Safari to see).

It is developers that will suffer for this. End users are already up in arms about privacy and demanding keyboards not use this feature whilst clients don’t necessarily understand what is going on and just see the negative feedback. I’ve been approached by a number of prospective clients to build these keyboards and so far I’ve put them off by showing them the ‘Full Keyboard Access’ search on Twitter.3

It seems to me to that Apple are treating the keyboard as a power feature and expect people to understand how it works under the hood. Seeing as some security savvy developers are cautious about installing these things, I think Apple has a lot of improvements to make in the way keyboards are installed, especially if it is to avoid negative fallout from end users who think that developers can steal your credit card number with an emoji keyboard. It’s good to be cautious about these things, but at the moment people are completely paranoid due to the installation process.

  1. That is if you call swiping an improvement. Sidenote: I hate that since iOS 8 a lot of people misspell the verb ‘swipe’ as ‘swype’ (as in “I can’t swype through this page in your app”) ↩︎

  2. It irritates me that PopKey is the more well known keyboard though. This is entirely due to the fact that it put up a really nicely designed teaser page in advance and has got a lot of press coverage. I think it is really bad they still use the tagline “The world’s first animated GIF keyboard” when it clearly wasn’t and has so many flaws compared to the app that came first. That it is featured by Apple in the Best New Apps section is a great shame. ↩︎

  3. For a while I tried to educate people as to how a GIF keyboard can’t read your iMessages. I gave up after a while. ↩︎

Showing TODO as a warning in a Swift Xcode project

I rarely use comments when I’m coding1. I do make one exception though; using // TODO: and // FIXME: to highlight pieces of code I need to revisit at a later date. The advantage of doing this is that the lines then show up in the jump bar popover in bold text with one-click access to the exact line:

TODO comments in the Xcode jump bar

The issue I have with this is that it is very easy to forget about them unless you are using the jump bar frequently. I used to log them in my todo manager, Things, but that duplicates the workload. It would be much more useful if those errors were flagged in some way…

Jeffrey Sambells wrote a post on how to flag these comments as Xcode warnings but that only applies for Objective-C. With a slight tweak, here is a run script build phase for flagging TODO: and FIXME: as warnings in a Swift project:

echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"

The result is an unmissable warning whenever you run your project.

TODO warnings in an Xcode Swift project

I don’t know about you, but I feel more compelled to clean up these yellow warnings than ticking things off in a todo list.

Swift 4.2 Update (18th September 2018)

It is now possble with Swift 4.2 to do something similar to the above without the need for a script build phase:

#warning("Some warning text")
#error("Some error text")

With #warning() and #error() you can now generate warnings and errors in code without the need for comments or a build phase. You may prefer to use comments still in which case the above still works with iOS 12 / Xcode 10 but this language-level support may be more beneficial in some situations.

  1. If your code needs commenting, it isn’t clear enough. Refactor until it is. If it doesn’t make sense because of semantics, rethink your naming conventions. ↩︎

« Older Entries Newer Entries »