03rd January 2018

This is just something small in Swift/iOS that I find pretty handy, so I thought I’d share it just in case it can help.

So, the problem is that creating data that has to be presented in a UITableView can be somewhat complex, especially if you have multiple columns. This solution is geared towards quickly creating dummy data, but I think it could be expanded into an overall DataSource solution.

Anyway, we’ll start with the current way of managing sections. Usually, you would have some kind of enum that would correspond to a section integer, and also however many arrays of data for the number of sections. You would then either use the section enum to find the correct array. Or maybe you’d use a 2d array, and then use it as the index.

It just doesn’t see very Swift to me. In Swift, everything is simple, easy to read, and is pretty easy to write. So I thought I’d come up with a slight abstraction.

My first idea was to just make two structs, one for a Section, and another for a Table:

struct Section {
    var title: String
    var items: [String]
}

struct Table {
    var sections: [Section]
}

You could then go ahead, create individual sections, and add them to one table. Easy.

Example Data

Animals:

  • Cats
    • Tiger
    • Lion
    • Lynx
  • Bears
    • Grizzly
    • Black
    • Polar

Example Code

let catSection = Section(title: "Cats", items: ["Tiger", "Lion", "Lynx"])
let bearSection = Section(title: "Bears", items: ["Grizzly", "Black", "Polar"])

let animalTable = Table(sections: [catSection, bearSection])

I just find that a bit more readable.

It also makes the number of sections and rows a bit simpler:

let numberOfSections = animalTable.sections.count
let numberOfRows = animalTable.sections[0].items.count

However, you can add this functionality to the Table struct Which makes it much, much better.

Here is the definition of the ComplexTable struct:

struct ComplexTable {
    var sections: [Section]
    
    func numberOfRows(forSection section: Int) -> Int {
        if sections.count > section {
            return sections[section].items.count
        } else {
            return 0
        }
    }

    func numberOfSections() -> Int {
        return sections.count
    }
}

Which would make it this easy to get the row and section counts:

let numberOfSections = complexAnimalTable.numberOfSections()
let numberOfRows = complexAnimalTable.numberOfRows(forSection: 0)

So there you go.

It’s nothing big, and it won’t win many programming awards. But it’s a small piece of code that will certainly help me when I’m just messing around with tables, or I want a really clean and simple way to store small amounts of organised data.

29th December 2017

So, Apple finally came clean with the battery stuff on older iPhones:

We’ve been hearing feedback from our customers about the way we handle performance for iPhones with older batteries and how we have communicated that process. We know that some of you feel Apple has let you down. We apologize. There’s been a lot of misunderstanding about this issue, so we would like to clarify and let you know about some changes we’re making.

First and foremost, we have never — and would never — do anything to intentionally shorten the life of any Apple product, or degrade the user experience to drive customer upgrades. Our goal has always been to create products that our customers love, and making iPhones last as long as possible is an important part of that.

The situation isn’t ideal, in that they’ve annoyed, and probably confused some of their customers by not making it transparent from the start.

However, the actual power management feature that people are complaining about, actually seems like a really good idea.

About a year ago in iOS 10.2.1, we delivered a software update that improves power management during peak workloads to avoid unexpected shutdowns on iPhone 6, iPhone 6 Plus, iPhone 6s, iPhone 6s Plus, and iPhone SE. With the update, iOS dynamically manages the maximum performance of some system components when needed to prevent a shutdown. While these changes may go unnoticed, in some cases users may experience longer launch times for apps and other reductions in performance.

I’ve seen a lot of news outlets saying that this is Apple trying to move people to newer iPhones, and even that it is causing iPhones to not last as long (Not the battery, but the actual device’s lifespan).

I can only see this update doing the exact opposite. It slowed down performance, but that is to extend the short term battery life, and also the long term life of the device.

The lack of communication is what messes everything up though. Even if you disregard the trust factor of Apple doing this without telling anybody, it leads users to believe that they are affected by it, when in some cases they might not be. So after seeing a small bit of news about Apple slowing down iPhones, someone with a completely unrelated device, or even an affected device with another issue, would more than likely blame this new power management update.

What Apple are doing about this, is actually quite impressive. They’re reducing the price of an out of warranty battery replacement by $50. But more importantly, they’re going to start making the battery heath more visible in iOS. It’s something you have on a Mac, and I will welcome it to iOS.

They could have avoided this whole situation though, as clearly they proved they can be transparent about this feature (although in this case it was forced). So why didn’t they write a small article about a “new power management feature” and how they’re extending the lifespans of older devices, and then just make the whole thing optional.

28th December 2017
Permalink

Jesse Watson has just published a time-lapse he shot of the recent SpaceX launch. You know, the one that looked really strange, and not like any rocket we’ve seen before. However the video is of course over a much longer period of time, and shows a wider angle of everything that went on.

He filmed it from Yuma Arizona, roughly 400 miles away from the launch site. And it took quite a bit of planning:

I scouted four locations that had foregrounds to add depth to the imagery and was uniquely inspiring to my hometown. Location choices were between a favorite local hiking mountain, the Imperial Sand Dunes, or a small hill that resides in the historic downtown area overlooking the city. I ended up choosing the location that overlooked the city, partially because it was the easiest to access with all of my time-lapse gear. I used The Photographer’s Ephemeris and Google Maps to help scouting and initial line up.

I have never shot a rocket launch before, so I did not know exactly what to expect as far as exposure or precise location of the rocket in the horizon. I wanted to be prepared to capture comprehensive coverage of the spectacle. Therefore I packed four cameras and five lenses, to cover wide to telephoto details of the scene. Three of the cameras were rolling time-lapse and 1 was setup for telephoto video.

It’s certainly an interesting story, and also a fantastic video.

Watch below in the embedded player, or if that fails, it’s on Vimeo along with his story.

SpaceX Falcon 9 Rocket Launch from Jesse Watson on Vimeo.

20th December 2017

In a recent article by Mark Gurman over at Bloomberg, he wrote over 600 words on the supposed plan that Apple have, which would converge apps from iOS and macOS. Meaning that developers would be able to design just one app, and have it work on both platforms.

I personally dont think this is going to happen.

And if you read the whole piece, you’ll find that only 48 words out of the total 672 are relevant:

Apple currently plans to begin rolling out the change as part of next fall’s major iOS and macOS updates, said the people, who requested anonymity to discuss an internal matter. The secret project, codenamed “Marzipan,” is one of the tentpole additions for next year’s Apple software road map.

I’ve been hearing Mark’s name for a few years, and people always seem to make him sound like a very top Apple reporter, which I guess is why he now writes for Bloomberg. But his latest rumours, have been a bit lower in quality in my opinion.

Read the “full” article on Bloomberg.

12th December 2017
Permalink

From the Twitter Blog:

We’ve made it easy to create a thread by adding a plus button in the composer, so you can connect your thoughts and publish your threaded Tweets all at the same time. You can continue adding more Tweets to your published thread at any time with the new “Add another Tweet” button. Additionally, it’s now simpler to spot a thread – we’ve added an obvious “Show this thread” label. – Full announcement.

As much as I think this is a good addition to the Twitter app, even though my thoughts on tweetstorms are mixed, I can’t help but thinking that they’re still not working on the important things.

Continue Reading

08th December 2017
Permalink

Ingrid Lunden writing for TechCrunch:

As Spotify continues to inch towards a public listing, Apple is making a move of its own to step up its game in music services. Sources tell us that the company is close to acquiring Shazam, the popular app that lets people identify any song, TV show, film or advert in seconds, by listening to an audio clip or (in the case of, say, an ad) a visual fragment, and then takes you to content relevant to that search.

We have heard that the deal is being signed this week, and will be announced on Monday, although that could always change.

Ever since Shazam was first integrated into Siri, I only ever thought of this as the long term solution. Simply buying them to tidy it all up would be worth it in my opinion. However I assume they will gain a lot more than just that.

Read the full article.

Continue Reading

08th December 2017

YouTube have again, of course, released their annual Rewind video.

I’m always impressed with the overall production quality of these videos, and maybe I’m forgetting the previous ones, but this looks really well made.

Continue Reading

07th December 2017
Permalink

Chris Sheldrick had an idea to make addresses better for the entire planet, and inside just one TED talk he explained how it works, the current progress, and how it can make everyones lives better.

With what3words, Chris Sheldrick and his team have divided the entire planet into three-meter squares and assigned each a unique, three-word identifier, like famous.splice.writers or blocks.evenly.breed, giving a precise address to the billions of people worldwide who don’t have one. In this quick talk about a big idea, Sheldrick explains the economic and political implications of giving everyone an accurate address — from building infrastructure to sending aid to disaster zones to delivering hot pizza.

Watch on TED.com, or below if the embedded video works.

Continue Reading