swift

  1. Wacky JSON

    In Swift, turning JSON content from a file or a server into structs or classes in code is much friendlier now that we have the Encodable and Decodable protocols. For simple cases you need to write almost no code and can quickly get on to something else. For example, if you see this: { "posts": [ "this is a tweet maybe", "this is something political", "I'm angry about something", "I made something cool" ] } You can decode it with very little code: struct PostPage: Decodable { let posts: [String] } let data = // Get this JSON from a file or the internet or your imaginination let decoder = JSONDecoder() let page = try docoder.decode(PostPage.self, from: data) This is all great for most cases, but what happens when API-makers stop being polite and things get real? What if your JSON looks like this: { "posts"

    Samuel Goodwin swift
  2. The Case of the Broken Buttons

    On a client project the other day, I spent most of the day tracking down a rather serious bug. All UIBarButtonItems were nearly un-tappable on iOS 11. These were not especially crafty buttons, most of them were using either an icon of reasonable size or a title. Some were even using the system standard items. None of them worked. Icons were un-tappable, back buttons were only tappable on the edges. All users on iOS 11 were left out in the cold and would not be happy. Instantly I assumed there was some clever code hiding somewhere that was causing the problem. I searched the project (this was a fairly new client so I did not know all of what lurked there) for subclasses of UINavigationController and UINavigationBar. I looked for categories and extensions on UIBarButtonItem as well as the navigation classes. I even assumed the problem was with one of

    Samuel Goodwin swift