Categories
Blog

sergio.blog

Last year Automattic, the company that I work for, bought the .blog domain  and being a generous company they decided to offer to all automatticians  the domain of their choice!

So say hello to my new domain: sergio.blog !!

So from now on I will start using this new home for my personal writing:  travel, review of co-work places, day to day events, music, books and rants.

I will keep sergioestevao.com going on but now more focused on my professional achievements, conferences and code projects.

Categories
Blog

Automattic GM 2016 – Whistler

This year the Automattic Grand Meetup was in Whistler village. The Grand Meetup is an annual event where all workers of Automattic meet in a single place, do new friendships renew some old ones, have fun together and plan the year ahead.
The week started with a big town hall where Matt Mullenweg (our CEO) answer all the questions, it lasted until 2 am. Then for the rest of the week we split into groups doing workshops, projects, and classes. The last two days were dedicated to fun activities: trekking, escape rooms, downhill bikes, beer festival, photo tours, zipline and others. It all finished with a bang with a big party on the last night, even a bear showed up!

 

 

Categories
Blog

Try Swift! NYC

This year I had the opportunity to attend Try Swift! NYC, a conference dedicated 100% to Swift development.

This is a fairly new conference, the first edition was back in March in Tokyo, but the organization level was excellent. From the initial website, the registration process, pre-conference events, the conference itself all was great.
It all started with a pre-meetup party on the Meetup headquarters in NY, the nice folks of Meetup did a quick introduction and talked about their new app, 100% made in Swift, and then send us to a rooftop dinner and drinks!!!

Next day the event itself was in the Axa Event and Production Center in downtown Manhattan , this was a one track event and it all happened on a good sized auditorium, all very comfortable and with excellent audio/video resources. The presentations and  speaker were of high quality and they ranged from beginner to advanced topics.

My favorite presentations were:

  • Random Talk: the Consistent World of Noise, excellent talk from Natalia Berdis about random algorithms and how to use it. Excellent  slides to show how different random algorithms works and when to use them.
  • Lambda: There and Back Again, from Rob Napier simple down to earth presentation on how to use functional programming in Swift.
  • Incremental Swift , Amy Dier talks on how Etsy is using Swift in their codebase. Very interesting to learn they try to keep everything done in Swift still easy accessible from Objective-C code.
  • Making rich text editor in Swift, Katsumi Kishikawa with a very detailed talk about all the things you need to be aware when working with text in iOS. I learned this the hard way some year ago when doing the Aljazeera app.

Besides the presentations/speakers, the great thing about the conference was the community that was present, everyone was super friendly and always available for a chat. The speakers themselves were super friendly and made time during their time there to answer any question that you could have, in fact after they did their presentation they were available for an hour to answer questions.

The organizers themselves had super attention to detail, they provided every morning a set of basic toiletries, in case you had forgot something while packing. They had a magician as a break entertrainer to keep people energized between presentations. Of course good coffee was always available and the meals provided where not bad at all.

The only hiccup of the conference was the Pizza and Party event of the first night, it was a bit disorganized and the pizza took forever! Quickly sorted out by going out to local Pizzaria recommended by NY local.

Definitely going back next year! Keep up the good work Natasha the Robot!

Categories
Blog

Crashes on iOS 10

I spent the last week watching Apple WWDC videos, and after downloading Xcode 8 I was testing several of my libraries and applications.

While testing the WPMediaPicker library I found that the sample app was crashing every time I opened the picker. After some investing on the code I found that the app was crashing the moment I was trying to use the PHPhotoLibrary class.

After some looking around in the documentation I found out this:

Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s photo library, must statically declare the intent to do so. Include the NSPhotoLibraryUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits.

Before iOS 9 if you tried to access the Photo Library without providing this key you will simple get a default warning but now it simple crashes the app.

And this isn’t limited to the Photo Library, this is now standard behaviour to all the libraries that need to have an UsageDescription key on the Info.plist file.

Here is a small compilation:

  • NSAppleMusicUsageDescription

  • NSBluetoothPeripheralUsageDescription

  • NSCalendarsUsageDescription

  • NSCameraUsageDescription

  • NSContactsUsageDescription

  • NSHealthShareUsageDescription

  • NSHomeKitUsageDescription

  • NSLocationAlwaysUsageDescription

  • NSLocationWhenInUseUsageDescription

  • NSMicrophoneUsageDescription

  • NSMotionUsageDescription

  • NSPhotoLibraryUsageDescription

You can find the full list here, just search for UsageDescription on the page.

If you still are not using these keys is time to start to update your applications and use this opportunity to provide a good text for your requests for permissions from  your app users.

Categories
Blog

JSON Deserialization in Swift

Some time ago when Swift was announced there was a big discussion in the iOS development community about JSON deserialisation and the right way to implement it. At the time, I didn’t give it much attention because I was still committed to Objective-C and didn’t have any immediate requirements to use Swift.

Fast forward two years and I’m now mostly programming in Swift and quickly found out the issues around JSON that everyone was talking about two years ago.

The main problems result from the way JSON parsing is done on iOS, the NSJSONSerialization object simply returns an AnyObject for you to handle, and because of Swift is very strictly typed you soon get code that is very verbose and hard to follow.

For example to read the photo URL from a JSON file like this:

[
  {
    "id": 1,
    "name": "Sergio",
    "weight": 70.5,
    "photos": [{
             "url": "http://fake.com/sergio.jpeg",
             "width": 100,
             "height": 200
             }]
  }
]

You will need to write something like this:

do {
    guard let url = NSBundle.mainBundle().URLForResource("sample", withExtension: "json"),
        let JSONData = NSData(contentsOfURL: url),
        let users = try NSJSONSerialization.JSONObjectWithData(JSONData, options: NSJSONReadingOptions()) as? Array<AnyObject>
        let user = users[0] as? [String: AnyObject],
        let photos = user["photos"] as? Array<AnyObject>,
        let photo = photos[0] as? [String: AnyObject],
        let photoURL = photo["url"]
    else {
        print("Ops... some error")
    }
    print("\(photoURL)")
} catch {
    print(error)
    return
}

While this is improved from early versions of Swift because of the addition of the guard statement and the new error handling, it’s still very verbose and if you need to track errors on the JSON file you need to split all the guard conditions in order to be able to find where things failed.

So I decided to implement my own library to allow less verbose code while reading values from JSON, but without using any custom operators or protocols like other libraries. Another goal was also to make it easy to find any mistakes made on the JSON files.

The end result was a single class called SVEJSONObject were you can write code like this:

    let url = NSBundle.mainBundle().URLForResource("sample", withExtension: "json")!

    do {
        let users = try JSONObject(url: url)
        let photoURL = try users[0]["photos"][0]["url"].string()
    } catch {
        print(error)
        return
    }

SVEJSONObject allows you to have simpler deserialization code by keeping types restricted to what is available in the JSON specification.

It also allows you to chain subscript calls like this:

users[0]["photos"][0]["url"].string()

And it makes error tracking easy by using Swift exception mechanism with a custom ErrorType that shows what went wrong. For example, if for some reason you tried to do this

users[0]["photos"][0]["link"].string()

you will get an JSONValidationError with this message:

Root[0]->photos->[0]: Missing "link" element in dictionary.

You can check the full code and documentation in the project repo in GitHub.

Categories
Blog

Our software must get “a lot” better

Great post from Seth Godin about the issues with “free” software. The examples he provides in the article are good ones but there is a plenty of good companies and individuals out there doing free software that is great, see WordPress, Linux, Slack and many others.

Categories
Blog Code

Logging in Swift

Here is my poor man version of logging for SWIFT

func logPrint(logMessage: Any, _ file: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) {
    print("\(file):\(line):0: \(function): \(logMessage)")
}

This method besides printing your message it shows the file name, the line and the function method where the log was made. The file, function and line numbers are extracted using literal expressions.

This makes it easier to find where the log message come from and if you have the KZLinkedConsole plugin installed in Xcode you just need to click on the error message in the console and Xcode will take you there.

For a more advanced logging library I recommend XCGLogger

== Update (2016-01-25) ==

I found out that the print statement doesn’t print to the System Logs, this could be useful in scenarios that you want to see the log message on a user device. So I update my method to use the NSLog function

func logPrint(logMessage: Any, _ file: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) {
    NSLog("\(file):\(line):0: \(function): \(logMessage)")
}
Categories
Blog

Apple TV Tech Talks – London

I attended the Apple TV Tech Talks in London this week. They are part of a tour that developers and designers from Apple are doing around world to show the possibilities of the new Apple TV and share some insights on how to design and develop for it. 

The presentations where all very good with a lot of suggestions on how to optimise/improve your app in terms of UI/UX and tech. Even more valuable where the coding and UI/UX workshops where you could present your questions directly to an Apple engineer or designer. You could even get design review from one of the UX experts from Apple.

In conclusion it was great and concise conference about tvOS, in a way I think they are better than the WWDC because they are more focused and a lot less crowded! It was also a great opportunity to connect with London developers community and see some old colleagues. I hope they do them again next year!

  
  

Categories
Blog

WordCamp Edinburgh 2015

I had a great time on WordCamp Edinburgh 2015, met some great people from the local WordPress community and enjoyed some great talks from the other speakers.

Here is the video of my presentation about the WP-REST API

and the slides:

The code for the app  show in the presentation can be found on this GitHub repo.

I also participated on the Roundtable about the future of the REST API:

#wcedin @wcedin

Categories
Blog Portfolio

WordPress iOS App

Role: Core Developer

Client: Automattic

Links: AppStore, GitHub repo

Inspiration strikes — anytime, anywhere. Manage your WordPress blog or website on the go, from your iOS device: view your stats, moderate comments, create and edit posts and pages, and upload media. All you need is a WordPress.com blog or a self-hosted WordPress.org site running 3.6 or higher. With WordPress for iOS, you have the power of publishing in the palm of your hand. Draft a spontaneous haiku on the train. Snap a photo on an afternoon stroll for the week’s photo challenge at The Daily Post. Respond to your latest comments, or monitor your stats to see where today’s readers are coming from.