wow people on twitter are mean

In a series of unintentionally hilarious tweets that sound more like something from an Onion article than real life, Brandon Carpenter, an iOS developer at Twitter, is getting an object lesson in what Twitter is like for the people who actually use it on a regular basis.

A quick look at his Twitter stream shows that he’s neither dumb nor short on empathy, but that he doesn’t post anywhere near as often as the sort of users who aren’t all that keen on the announced changes to the way the timeline is going to work. He certainly doesn’t post as often as I do, and in my circles, I’m sure I’m merely a moderate user. Working on one of the most heavily-used mobile apps on the market is a big cognitive load to carry, and I suspect that along with being a husband, dad, and someone who has to pay rent in San Francisco, his Twitter experience is different from those of the people who make their day, their name, or their living using it. I call this difference in experience between the people who developer applications and its heavier users “the developer-user gap”, something captured quite well in the line from William Gibson’s Neuromancer: “The street finds its own uses for things.”

The fact that the developer-user gap exists highlights an oft-forgotten role that a technical evangelist can play. Companies try to make sure that their evangelists, community managers, social media people, and the like are sending out the right message to their customers and partners, but forget that communication can work in the opposite direction. A good evangelist will make sure that users get the message, but a great one will make sure that the users’ messages get back to the company as well.

Kudos to Brandon for taking this tweet sent to him…

…and responding with grace:

It’s often a thankless job, but as a regular user of Twitter’s iOS client, thanks for all your work, Brandon. I salute you with a filet mignon on a flaming sword!

But fire up your Twitter client and use it a little more, willya? It’ll help you make a better app.



Lately, I’ve been seeing a number of half-baked implementations of a function that splits a floating-point number (Floats, Doubles, and the like) into a whole number and fraction part. For example, given the value 3.141592, it should return:

  • The whole number part: 3, and
  • the fractional part: 0.141592.

There’s no need to come up with your own implementation: there’s a function in C’s math library, and many programming languages, Swift included, give you access to it. It’s called modf, and in Swift, it works like this:

Since C doesn’t have a tuple type, you call modf differently. Here’s the function’s signature:

Its return value is the fractional part, and the whole number value is put into an extra variable whose address you provide. If you’re working in Swift and feeling homesick for the pointer-y stuff you have to do in C, you can call modf this way:

But seriously: do it the first way. It’s more Swift-like (Swift-esque? Swifty?).


star wars uber logo 1

Click the photo to see it at full size.

“Well, the Empire doesn’t consider a small one-man fighter to be any threat, or they’d have a tighter defense. An analysis of the plans provided by Princess Leia has demonstrated a weakness in the battle station. But the approach will not be easy. You are required to maneuver straight down this trench and skim the surface to this point. The target area is only two meters wide. It’s a small thermal exhaust port, right below the main port. The shaft leads directly to the reactor system. A precise hit will start a chain reaction which should destroy the station. Only a precise hit will set off a chain reaction. The shaft is ray-shielded, so you’ll have to use proton torpedoes.”

star wars uber logo 2

Click the photo to see it at full size.

For those of you who don’t remember the film, here’s the original still:

original scene

Click the photo to see it at full size.

For those of you who are insatiably curious (and hey, if you’re reading this blog, the odds are good that you are), here’s Larry Cuba explaining how he made the computer graphics for the Death Star briefing in Star Wars. Remember, this was the 1970s!


Concatenating strings in Swift: Which way is faster?

by Joey deVilla on February 3, 2016

which is faster

Creative Commons photo by Jaguar MENA. Click to see the source.

Stack Overflow user “James” asked:

Which is the quickest, and most efficient way to concatenate multiple strings in Swift 2?

Or is the only differentiation the way it looks to the programmer?

It’s not worth worrying about the speed of string concatenations when you’re doing them, once, a dozen, a hundred, or even a thousand times. It may start to matter with larger quantities of larger strings. I decided to run a quick and dirty benchmarking test, which you should take with the appropriate number of grains of salt. Here’s the important part of my code:

You may have noticed that I used _ (underscore) characters to make the size of the for loop, 100000000, easier to read, just as we in North America use commas and people elsewhere use spaces or periods. Swift, along with a number of programming languages, lets you do this — take advantage of this and make your code easier to read when dealing with large numbers!

Using the + operator to concatenate strings as shown in James’ example, here’s the average time as reported by the app running in Debug mode over a dozen runs:

  • 1.4 seconds on the simulator on my MacBook Pro (2014 15″ model, 2.5GHz i7, 16GB RAM), and
  • 1.3 seconds on my iPhone 6S

Then, after changing the line after the Here’s the concatenation comment to:

I ran it again and got these results over a dozen runs:

  • 50.9 seconds on the simulator
  • 88.9 seconds on the iPhone 6S

Running on the phone, the + method is almost 70 times faster, which is a significant difference when concatenating a large number — 100 million — strings. If you’re concatenating far fewer strings, your better bet is to go with the option that gives you the more readable, editable code. For example, this is easier to follow and edit:

than this:


My proposed changes to Uber’s new logos

by Joey deVilla on February 2, 2016

ubers new logos fixed

If you want to see what Uber’s new logos — one for riders, one for “partners” — really look like, check out their news release.



VentureBeat have posted their report on IDC’s quarterly tablet sales tracker, and like Business Insider before them, they were content to simply publish screen shots of IDC’s tables.

Here at Global Nerdy, we like to do a little more to help you better understand the numbers. So here are:

  • Some nicely-formatted versions of IDC’s tables
  • The data from those tables turned into graphs
  • A downloadable spreadsheet so that you can play with IDC’s numbers.


Top Five Tablet Vendors, Shipments, Market Share, and Change, Fourth Quarter 2015

Shipments are in millions of units:

4Q14 Unit Shipments 4Q14 Market Share 4Q15 Unit Shipments 4Q15 Market Share Year-Over-Year Change
Apple 21.4 28.0% 16.1 24.4% -24.8%
Samsung 11.0 14.4% 9.0 13.7% -18.1%
Amazon 1.9 2.5% 5.2 7.9% 175.7%
Lenovo 3.7 4.8% 3.2 4.9% -13.5%
Huawei 1.0 1.3% 2.2 3.3% 124.6%
Others 37.4 49.0% 30.2 45.8% -19.2%
Total 76.4 100.0% 65.9 100.0% -13.7%

top tablet vendors 1

Top Five Tablet Vendors, Shipments, Market Share, and Change, 2015

Shipments are in millions of units:

2014 Unit Shipments 2014 Market Share 2015 Unit Shipments 2015 Market Share Year-Over-Year Change
Apple 63.4 27.6% 49.6 24.0% -21.8%
Samsung 39.8 17.3% 33.4 16.1% -16.1%
Lenovo 11.2 4.9% 11.2 5.4% 0.4%
ASUS 11.8 5.1% 7.1 3.4% -39.9%
Huawei 3.0 1.3% 6.5 3.1% 116.6%
Others 100.9 43.9% 99.1 47.9% -1.8%
 Total 230.1 100.0% 206.9 100.0% -10.1%

top tablet vendors 2

download excel spreadsheet Click here to download the spreadsheet with IDC’s numbers.


touching ipad screen

In the previous article in this series, we looked using actions to create complex sprite movements with very few lines of code. As this series progresses, we’ll work our way towards building complete games.

In this article, we’ll look at responding to user’s touches on the screen.

Set up a new project

It’s time to do the File → New → Project… dance again! Open up Xcode and create a new Game project:

new project

When it comes time to name the project, give it an appropriate name like RespondingToTouches (that’s the name I gave my project).

Once again, we’ll set the game to that it’s landscape-only. The simplest way to restrict our app’s orientation to landscape is by checking and unchecking the appropriate Device Orientation checkboxes in the app’s properties. Make sure that:

  • Portrait is unchecked
  • Landscape Left and Landscape Right are checked

uncheck portrait

Click the screenshot to see it at full size.

You can confirm that the app is landscape-only by running it. It should look like the video below, with spinning spaceships appearing wherever you tap the screen. It shouldn’t switch to portrait mode when you rotate the phone to a portrait orientation:

Making the spaceship go to where you touch the screen

It’s time to make our own interactivity. Let’s make an app that puts the spaceship sprite in the center of the screen, and then has the spaceship sprite immediately go to wherever the user touches the screen.

Open Gamescene.swift and replace its code with this:

First task: drawing the spaceship sprite in the center of the screen. Before you look at the code, see if you can do it yourself. There’s enough information in the previous article to help you do this, or you can follow these hints:

  • A sprite is an instance of the SKSpriteNode class, and given the name of an image, you can instantiate one by using SKSpriteNode‘s init(imageNamed:) method.
  • A game scene’s didMoveToView method is called when the scene is first presented, and it’s the perfect place to do things like setting sprites in their initial locations.
  • A sprite’s location onscreen can be set using its position property, which is of type CGPoint, a struct that holds 2 Floats: one for the x-coordinate, and another for the y-coordinate.
  • The frame of a scene is the rectangle — a CGRect — that determines its bounds. You can get its width and height through the properties bearing those names.
  • You might want to scale down the spaceship sprite to one-third of its size. The setScale method will do that.
  • To display a sprite in a scene, you need to use the addChild method.

Your code should look something like this…

…and when you run it, it should look like this:

spaceship in the middle of the screen

If you were to touch the screen, nothing would happen. That’s because there’s no code to respond to touches on the screen…yet! We’ll start by adding code to the touchesBegan method.

touchesBegan is called when the user puts a finger on the screen. It provides information about that touch action in its touches<c/ode> argument, a Set of touch objects, which are instances of the UITouch class. One of the properties of UITouch is locationInNode, which is a CGPoint. Given that sprites have a position property that is also a CGPoint, you've probably already guessed what we're about to code.

The default setting for multitouch in an app is “off”. We want to keep things simple for now, so we’ll just go with the default, which means that the app will register only one touch at a time, which in turn means that touchesBegan‘s touches argument will only contain a single touch object. We’ll retrieve that object from touches by using Set‘s first property.

Try coding it yourself before looking at the code below:

If you run the app, you’ll see that the spaceship jumps to wherever you put down your finger:

Making the spaceship go to where you released your finger

You’ll notice that if you hold your finger on the screen and move it about, the ship doesn’t follow your finger. It just stays where you first touched the screen and doesn’t move until you remove your finger and touch some other point.

The name touchesBegan implies that it has a counterpart method for when the user releases his/her finger from the screen. That method is called touchesEnded, and it takes the same arguments as touchesBegan.

Start typing touchesEnded into GameScene, and Xcode’s autocompletion should make it simple for you to set up a touchesEnded method. Cut the code from touchesBegan and paste it into touchesEnded, like so:

Note what happens: the spaceship doesn’t move when you touch the screen until you remove your finger. Only when you release your finger does it move, and it jumps to the location where you released your finger from the screen. Try touching the screen, moving your finger to another location on the screen, and then releasing your finger.

What if we put the same code into both the touchesBegan and touchesEnded methods, like this?

If you run the app, the spaceship now jumps to the location where you made initial contact with the screen, and again to the location where you released your finger.

Making the spaceship follow your finger as you move it

You’re probably wondering if there’s a method that responds to changes that occur between the touchesBegan and touchesEnded events, something that lets you track the movements of the user’s finger as it moves on the screen. There is, and it’s called touchesMoved. It takes the same arguments as touchesBegan and touchesEnded, which means that it should respond to the code that we put into those two methods. Copy and paste the code from either touchesBegan and touchesEnded and paste it into touchesMoved. Your code should look like the following:

Run the app. It should look like this:

You’ll find that the spaceship jumps to the location where you touched the screen and as long as you keep your finger on the screen, you can drag it around. When you release your finger from the screen, the ship stays at the location where you released your finger.

Let’s refactor the duplicate code in touchesBegan, touchesMoved, and touchesEnded into its own method, handleTouch. The code will now look like this:

Experimenting with actions

Let’s combine this article’s lessons with the ones from the last one. Can you create some actions that make the spaceship pulsate as long as the user presses on the screen, as shown below?

Before you look at my solution below, see if you can’t code it yourself first:

You may have noticed that in the touchesEnded method, the spaceship sprite is restored to its normal scale with an action rather than by simply setting its scale using the setScale method. I found that simply setting the spaceship back to its normal scale with setScale a little too abrupt; restoreScaleAction makes the transition very smooth.

What we just covered

In this article, we covered:

  • A recap of:
    • Starting a new Game project in Xcode
    • Restricting an app’s orientation to landscape-only
    • Drawing sprites at a specified location on the screen
  • Responding to the event where the user touches the screen with the touchesBegan method
  • Responding to the event where the user stops touching the screen with the touchesEnded method
  • Responding to the event where the user moves his/her finger while touching the screen with the touchesMoved method
  • Combining actions with touch events for interesting visual effects.

In the next article in this series, we’ll look at moving player characters around the screen.

Previous articles in this series

  1. Writing iOS games with Swift and Sprite Kit, part 1: The power of actions