Kuba Suder's blog on Cocoa and web development

Cocoa JSON parsing libraries

Categories: Cocoa, iPhone 4 comments

Update: A new post from December 2010 with updated stats is available here.

For a few weeks I’ve been working on a new iPhone application.

Like most of other Cocoa apps I’ve written so far, this app also includes a JSON parser to load some kind of data from a server. The first thing the application does when it starts is connect to the JSON API, download a data file (about 100 KB) and parse it. This used to take about 10-15 seconds on the device, and I thought it was reasonable until I noticed that the HTTP response actually arrives after a second or so. So what was it doing for the rest of the time? I had to find out.

So I did some debugging, and it turned out that the 10 seconds are spent just on parsing the downloaded JSON file. That’s pretty bad… Like in all previous apps, I used an open source library BSJSONAdditions, which I knew wasn’t the fastest one available, but I never had any major problems with it before. On the other hand, I never tested it on a 100 KB file…

I knew there were a few other JSON parser libraries in ObjC, so I decided to make a small benchmark and see how well they all compared to the one I used. The other libraries I tried were: JSON Framework, TouchJSON and YAJL.

Read more »

Hello, iPhone!

Categories: Cocoa, iPhone 0 comments

For the last few months, I’ve been spending a lot of time learning how to create apps for the Mac. Since I’m slowly starting to run out of new tutorials to read, I’ve decided to find myself something new to learn ;) Well, not completely new, actually, as a lot of that knowledge about Cocoa is going to be very useful.

I’m talking about iPhone development, of course. I bought an ebook about iPhone SDK from Pragmatic Programmers some time ago, which looks very promising, but I didn’t really start learning, because I wanted to get the iPhone development certificate first, and that took some time. You see, Apple’s platform is so damn open that to install even a “Hello world” on your own phone, you have to have a set of certificates from Apple, which they give you only after you register for an “iPhone developer program” which costs 100$. Really, guys, this is not how you attract developers to a platform… :\

Anyway, I got the certificates now, so I was finally able to run the “Hello world” on my phone :) Here’s a proof:

Hello iPhone (screenshot of my first application)

Read more »

The Dark Side of Cocoa

Categories: Cocoa 6 comments

An empty cup of cocoa
Photo by Alexander Staubo (CC)

Some time ago I wrote about all the things that I loved in the Cocoa framework. This time, I’d like to write a bit about the worse side of Cocoa – the things that annoy me, confuse me, and make me wonder who the hell came up with such an idea…

So, the things that dislike in Cocoa are:

  • Long names. I know, some people say that explicit is better than implicit, also, there are no namespaces in ObjC, which may explain some of that. But I’ve seen names which really belong on The Daily WTF. The longest I’ve found so far is “NSManagedObjectContextObjectsDidChangeNotification” (51 characters), and I’m worried that this might not be the longest one yet… Are you telling me a name that takes half a line in my editor is more readable than a short one? Seriously?

Read more »

Interface Builder tips and tricks

Categories: Cocoa, Mac 1 comment

I read Apple’s tutorial about Interface Builder this week. Most parts of it told about rather basic things and were quite boring, but I’ve learned several useful tricks from it. IB, like most of Apple’s applications, has lots of hidden features which aren’t obvious at first, and can only be found by experimenting, by accident or by reading about them somewhere. Here’s a few things that I’ve learned from the tutorial – some of them are such hidden features, some are just things that weren’t mentioned in any source I’d read before.

Read more »

Generating scaffold interfaces in Cocoa

Categories: Cocoa, Mac 0 comments

I discovered an interesting feature in Interface Builder a few days ago. It seems that it can generate a scaffolding UI for you based on a CoreData model. It works like this: first you have to design a data model in XCode model editor (which you have to do anyway if you want to use Core Data; if you don’t, it won’t make sense to draw the model only to get the scaffold UI, it will be faster to make it yourself…). Let’s say you have a model like in this picture:

XCode data model editor

Read more »

Missing controls in IB 3.1

Categories: Cocoa, Mac 0 comments

I’ve upgraded XCode and Interface Builder to version 3.1 recently (the update doesn’t appear in the system update, you have to download it manually, and it’s deceitfully hidden – you have to register at Apple’s developer portal to get it…). Today I’ve noticed that after the update some advanced controls were missing in IB. I had a vague memory of having a lot of additional categories of controls below the standard ones (some image views and Quicktime controls, for example), and I couldn’t find them there. This screenshot confirmed that I wasn’t imagining it. Not that I need them right now, but I might need them one day…

I was able to figure this out after a bit of googling, so I’m posting a solution here so that maybe I’ll save someone a little time. The thing is, for some reason IB forgot about some of its plugins; I think it has something to do with the “known issues” entry here in the release notes. Plugin files are located inside system frameworks. Anyway, to get them back, you need to go to IB’s Preferences → Plugins, and using the plus below the list add several framework bundles from /System/Library/Frameworks. The list more or less matches the list from the release notes, but you’ll have to experiment a bit (e.g. ImageKit and Quicktime plugins were hidden inside Quartz, and DiscRecording inside DiscRecordingUI). And that’s it, all advanced controls are available again.

Addicted to Cocoa

Categories: Cocoa 0 comments

A cup of cocoa
Photo by Sharyn Morrow (CC)

For the last several weeks, I’ve been learning a lot about ObjectiveC and Cocoa programming. It’s really addictive… I just can’t stop myself sometimes :) I’m reading the “RubyCocoa” book from Pragmatic Programmers and “Cocoa Programming for Mac OS X” by Aaron Hillegass. I also read some online tutorials – on Apple’s site, on Cocoa Dev Central (I love the illustrations there!), or elsewhere (check out my Cocoa bookmarks on Delicious for more).

The more I learn about Cocoa, the more I like it. It does have its problems which annoy me sometimes, but in general, it seems to make programming GUI applications really easy once you learn it. You can do really amazing things by calling just a few methods, and even better – you can create simple applications while not writing ANY CODE at all. So much can be done by connecting things in the Interface Builder, that sometimes you don’t need much more…

Here is a list of some of the things that I like in Cocoa:

Read more »