Categories
Development iOS Mac

Swift, REST, and JSON

I’m fond of a site called The Pastry Box Project. It’s a collection of thoughts and stories by a bunch of great writers, but that’s not why I mention it. I mention it because I noticed they had a nice, simple, REST API. Nifty!

PastryKit

Since I really enjoy writing code that communicates with services, and I needed a little project to learn some Swift, I thought I’d write a couple classes, I call PastryKit, that implement the Pastry Box REST API in Swift.

PastryKit is just two classes:

  1. PastryKit – Allows you to communicate with the Pastry Box REST API.
  2. Pastry – This is an entry returned by a call to PastryKit.

You can read more about The Pastry Box API on their site.

private func showPastryBaker() {
     var pastryKit = PastryKit();
     pastryKit.thoughtsByBaker("mike-monteiro", completionHandler:{(pasteries, error) in
          if (nil != error) { println(error) }
          if (nil != pasteries) { println(pasteries) }
     });
}

The Heavy Lifting

Most of the “heavy lifting” is performed in one place in PastryKit.swift in the private getWithIngredient function. It makes use of NSURLSession, which was introduced in iOS 7. Go find that function if you’d like to see how to do an HTTP GET in Swift. This is a simple case, it doesn’t require any authentication, or messing around with headers, and it only does GET’s. Doing a POST, PATCH or DELETE would, of course, require some changes, but you get the idea.

    /// getWithIngredient - worker method that does all gets
    private func getWithIngredient(ingredient: String?, completionHandler: (([Pastry]!, NSError!) -> Void)?) {
        let url = ((ingredient) != nil) ? NSURL(string: PastryBoxUrl + ingredient!) : NSURL(string: PastryBoxUrl)
        let request = NSURLRequest(URL: url!)
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        let session = NSURLSession(configuration: configuration, delegate: self, delegateQueue: nil)
        let task : NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler:{(data, response, error) in
            if (error == nil) {
                var conversionError: NSError?
                var ingredientsArray: NSArray = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.AllowFragments, error:&conversionError) as NSArray
                if (conversionError == nil) {
                    var pasteries = Pastry.pastryArrayFromNSArray(ingredientsArray)
                    if (completionHandler != nil) {
                        completionHandler!(pasteries, nil)
                    }
                }
                else {
                    println(conversionError)
                    if (completionHandler != nil) {
                        completionHandler!(nil, conversionError)
                    }
                }
            }
            else {
                println(error)
                if (completionHandler != nil) {
                    completionHandler!(nil, error)
                }
            }
        });
        
        task.resume()
    }

Go Get It!

The code is available on GitHub if you have need to get stuff from The Pastry Box Project in your Swift or Objective-C app.

Enjoy!

Categories
Development Objective-C Work Note

Work Note: Conditional Breakpoints in Xcode

If you’ve been developing for any period of time you’ll understand that the debugger is your friend. This tip is probably not new to a lot of folks, but I thought I’d share for anyone new to Xcode, Cocoa, and Objective-C development.

The Conditional Breakpoint

We’ve all set breakpoints in Xcode while debugging, but did you know you can set conditional breakpoints? Let’s say you’re processing a large quantity of data and you say to yourself “Man, I wish I could break right here when the value of this string is ‘labs'” Guess what, you can. Two easy steps

Step #1: Right click (Command-Click) on the breakpoint and select Edit Breakpoint…

Edit Breakpoint in Xcode

Step #2: In the popover type “(BOOL)[documentName isEqualToString:@”labs”]” into the Condition field.

Xcode Breakpoint Condition
That’s all you need to do! In this case the breakpoint will be skipped until documentName is “labs.”

Categories
Development

Team vs. Tools

objc.io [Brent Simmons]: It almost doesn’t matter what the details are — how we’re organized, what we use for source control management, and so on — because a great culture makes for a happy team that will figure out how to work together. And Omni has done a great job with that.”

Omni is one of the class acts in all of software. They’ve created a culture of greatness. If you didn’t know Omni has been doing Cocoa since before it was Cocoa. They started off writing code for NeXT boxes long ago. Their suite of productivity tools for Mac and iOS are unmatched. 

If you have the opportunity go listen to The Record #6 – Tim Woods (hosted by Chris Parrish and Brent Simmons, listen to the entire series, it’s really great.) This episode will give you a bit of Omni history. 

It’s all about the team in the end, not the tools.

Categories
Development

Native v. Web

Duct Tape, fixer of all things!Six Colors: “Most apps are just thin layers on top of modern Web standards with the added benefit of a potentially superior user-interface experience, because the operating system takes care of more details with greater consistency, and allows a complicated but more reliable adaptation to multiple sizes of devices, whether it’s iOS, Windows Phone, or Android.”

Yes, folks are still talking about native vs. web. Without the web most modern day apps would be less useful and in many cases useless. Social apps only work with a connection to services running on the web. We still need sites to provide access to the masses, a way to get data on any device.

There will probably come a day when the browser can outright replace native apps, but it’s not here yet. Web technologies are still very young and ever evolving. Heck, you can only use one language in the browser, that’s way too limiting. When the browser matures to the point it allows developers to control the entire experience and is open to the language of the developers choosing, I think we’ll see some remarkable apps. Until then we still need the native experience.

Categories
Development iOS

Sigh

Sigh: “Because you would rather spend your time building stuff than fighting provisioning.”

Just putting this here for later. Provisioning is one of the most frustrating chores I’ve ever had to do as a developer. Just Google “provisioning profile problems” and read the frustration it causes.

This is the one thing I wish Apple would spend some time on.

Categories
#twitter Development Indie iOS Mac

What happened to Twitterrific 5 for Mac?

Ollie! The Twitterrific Bird9TO5Mac: “By limiting the ability of third-party developers to create unique and useful clients for its service, Twitter is ensuring that new users will be forced to use one of its first-party solutions, whether that’s Twitter for Mac, TweetDeck, or the web. Unfortunately, none of these products are really worth using, and Twitter is shooting itself in the foot by attempting to drive users to these subpar experiences.”

There’s the problem in a nutshell. Twitter has been less than friendly to developers who can help them make a better experience for their users. Let’s say Twitter changed their rules to allow folks to develop clients that they don’t consider their bread and butter. What if you could create a client, free of limits, that wasn’t for web or mobile? This would open the door to a great update from The Iconfactory and allow other indie developers to create great native experiences for Windows or Linux. Seems like good business to me.

Categories
Development

Tumblr Colossus

Tumblr Engineering: “Written in Scala and built on NIO and the Akka actor framework, Colossus has had a huge impact on the way we build services at Tumblr.”

Scala is the new hotness. Everything else is old and busted.

IMG_3422.JPG

Categories
Development

Fear of Public Speaking

As I mentioned earlier I’m looking for a new gig, so I’ve been interviewing with folks. I’ve had a couple of interviews where they’ve asked me to look at code or write code. I’m absolutely horrible at this. When I’m put on the spot I break out in a sweat, really I do. I don’t know why, but I get super embarrassed, and I cannot think, at all.

Last Wednesday I was asked to solve the FizzBuzz problem. I fizzed out, why? I just cannot perform in an environment with people staring at me, on the spot. It’s just the way I am, and it means if I have to do whiteboard coding exercise, I’m most likely screwed because I can’t think logically.

Anyway, back to FizzBuzz. After leaving the interview my wife and I drove around the city, had lunch, and generally tried to make a day of it. On the way home I decided to pop out my MacBook and do the FizzBuzz exercise from memory. It took me less than five minutes to make the logic work as expected, then I “fancied” it up for my own sake.

Here’s the answer in a few lines of C code.

static void FizzBuzz()
{
    static int kBufferMax = 256;
    
    char outputBuffer[kBufferMax];
    
    for (int x = 1; x <= 100; x++)
    {
        memset(&outputBuffer, 0, kBufferMax);
        if (0 == (x % 3))
        {
            strcpy(outputBuffer, "Fizz");
        }
        if (0 == (x % 5))
        {
            strcat(outputBuffer, "Buzz");
        }
        
        if (outputBuffer[0])
        {
            printf("%s - value %d\n", outputBuffer, x);
        }
    }
}

Pretty simple, isn’t it? Here’s a Gist if you’d like.

I also have a fear of public speaking. I’ve managed to get over some of this by making sure I know my material cold when I’m speaking. It makes a huge difference, but in an interview you never know what you’re going to be asked to do. That alone sets me up to fail at the whiteboard. I’m nervous before I start.

Categories
Apple Core Labs Business Development Indie iOS Life

Into the Fray

I Have Failed

Will code for...Back in June I decided I’d jump back out into the Freelance iOS world and make a go of it. I had a couple contracts lined up so it seemed like a good time to make another run at it. Boy, was I wrong. About that time a number of well known Indie software developers were writing about their experiences in the App Store. The market for Indie work has kind of collapsed and I can tell you the Freelance market has bottomed out in many ways. It’s difficult to get folks to understand a mobile application is a real application. I hope someone is studying the psychology surrounding this phenomenon. I know every freelance developer has experienced this in their field. You give an honest estimation of time and an associated dollar value, and you never hear from them again. I hear fellow developers saying “Yep, been there, done that.” It’s just how things work.

Some of the contract work I’ve taken over the past couple of months are jobs I should not have taken. The pay was substantially less than it should have been and at least one of the applications was so substantial in size I really should have walked away, but I didn’t. That’s a big mistake on my part, something I regret, and a mistake I cannot make again. I took the work because I needed it. It’s a horrible position to negotiate from. You have zero power.

I also had a contract that went about as sideways as one could go. That is a cautionary tale and one I hope to tell someday, but not now.

All of this is, of course, a self made disaster. I chose to take the work, it’s something I’ll have to struggle out of, in the meantime I’m back out on the market, looking for a full-time gig.

What Do I Offer?

I’m a seasoned developer. You can call me old, that’s fine, I am not a 20-something. I have a wealth of experience shipping software. I’ve lead teams of developers and I’ve been an individual contributor. I know how to ship software. I’ve been there many times.

Most of my experience lies on the client side of the world. Windows desktop and iOS primarily. I’ve written code in C, C++, Objective-C, and C#. I have had a couple of stints writing software that ran on the server; Paramount Farms and LEVEL Studios come to mind. Both times the server side code was developed using a full Microsoft stack; C#, .Net, and SQL Server.

I believe connected services are the obvious thing to be doing. Along those lines I have experience developing and consuming services. REST and JSON based services are where it’s at today, but I’ve also consumed SOAP/XML based services. It’s all data, but I really do like the simplicity of REST/JSON.

I still like writing software but I’d also be more than happy to take on a Development Lead or Program Manager role. My last full-time position, with Pelco, was leading a team of 8-12 folks (it fluctuated in size and I’m counting contracted developers) developing a C++ and C# SDK for use with the Pelco VMS and I really loved what I was doing. I didn’t leave because I was unhappy, I left because iOS was calling me.

I’d love to continue working on iOS Applications, if possible, but I’d be equally happy working on desktop or server side software. I will warn folks up front. My SQL skills are pretty crude, but doing application logic and user interface isn’t a problem and is something I quite enjoy.

Career Highlights

I’m not much of a salesman. I don’t interview well (Whiteboard code? Instant fail, test anxiety.) I say this because I’ve had some of these moments recently. That’s the bad side of me.

I thought I’d share some things I have done and are in use by millions of people worldwide.

  1. Visio – I worked on Visio for over 10-years. QA, Setup Developer, Developer Support, and Visio Engine Development. When I left in 2003 Visio was used by over 9-million people worldwide.
  2. Pelco Endura – I worked on the Pelco line of Decoders for five years. This included the Workstation, VCD, and our shared pipeline component framework; MPF (Media Processing Framework.)
  3. Pelco SDK – I worked with a talented group of folks to create a reimagined SDK. We were able to design a new object-oriented C++ and C# SDK. I love creating code for others to use.
  4. LEVEL Studios – While at level I contributed to web services used by a large Android handset manufacturer. At the time the project was handed off our client it was supporting over 8-million people worldwide.
  5. Freelance – While freelancing I helped with a few applications, some are no longer in the store, and I have created a couple apps of my own (both in desperate need of a facelift, I know.)

If I were to sum up what I can offer I’d say this. I know how to ship software, how to make those tough decisions, and I can see the big picture. I know, and understand, that business needs play a big role in product development. I can lead or follow.

Categories
Development Objective-C Work Note

Work Note: That compiled?

I just ran across something that had me stumped for a while, I just couldn’t see it, and I would have thought the compiler would have choked on it. It didn’t, it built, and ran, and produced interesting results.

Confession time: I’m not using auto layout, yet. Why? I haven’t had the time to commit to it. Yes, I’m aware it would probably save me time in the long run. I will learn it, of course, just not today.

Anywho, back to the story.

I hade some code that looked like this, I must have been distracted mid-thought, and did a build. This code built.

self.thingView.frame = frame;
self.thingView.frame

AHHHHHH!Anyone see a problem there? No assignment, no closing “;”. The code built and ran! The outcome was my view moving into strange positions during rotation for no apparent reason. Wow.

I finally had to do a diff to find it, I just couldn’t see it.