jb… a weblog by Jonathan Buys

Misunderstanding NSString

So, while I was debugging the first post using Scout, I found an oddity in NSString. I was building the links between the posts using stringByAppendingPathComponent, to join the site’s base URL with the path component of the individual post. Unfortunately, that method seems to be stripping one of the forward slashes off of the http:// string, which screws up building links.

January 19, 2013 - 2 minute read - farmdog cocoa

From Zero to the App Store

This past Thursday I was privileged to speak at our local CocoaHeads about my history, and how I was able to bring my app to market. Since someone on Twitter asked for my slides, which don’t amount to much, I thought writing up my experiences would be a little more useful.

January 16, 2011 - 7 minute read - farmdog indie cocoa

Personal Rules for Cocoa Happiness

  1. Understand every line of code written in my apps
  2. Use frameworks sparingly (see rule 1).
  3. Do not copy and paste code (see rule 1).
  4. Add lots of comments so I remember what I was doing at any given time.
  5. Manage memory as I go, don’t wait until I’m nearly finished and then go and “clean it up”.
  6. Draw out the application on paper before writing a single line of code.
  7. Search Apple’s documentation, CocoaDev mailing list archives, Google, and anything else I can think of before asking for help.
  8. When programming, quit Mail, Twitter, NetNewsWire, and IM. Turn on some non-distracting music in iTunes.
  9. Get a cup of coffee.
  10. Remember, “This is hard, you are not stupid.”

June 29, 2009 - 1 minute read - programming cocoa

Ping from Cocoa

One of the features of Servers.app is that it pings the host and shows a little indicator for it’s status: green is good, red is dead. Getting that little feature in here was not quite as easy as I thought it would be. After searching the Apple documentation for what seemed like years, I stumbled across SimplePing. It was perfect, exactly what I was looking for. I dropped the two source code files into into my project, read through the documentation commented out in the header file and added the code to call SimplePing. It worked, and everything seemed fine. Except that it kept working, even when I knew for certain that the host did not exist.

So, I started digging through the source code for SimplePing.c, and found that instead of calling a standard error message, it called perror, which, according to the documentation, doesn’t return a value. This is fine if you want to log the ping results, but I wanted to ping the server and make a decision based on code. So, I changed a couple of lines of code from this:

if (error == 0) //was able to wait for reply successfully (whether we got a reply or not)
    if (gotResponse == 1)
		{numberPacketsReceived = numberPacketsReceived + 1;}

to this:

if (error == 0) //was able to wait for reply successfully (whether we got a reply or not)
    if (gotResponse == 1)
		{numberPacketsReceived = numberPacketsReceived + 1;}
	} else {
		error = 1;

Simply adding an extra else statement in there to return an error code gave my application something to work with. Now, from my application controller I can call SimplePing like this:

int systemUp;
systemUp = SimplePing(cString, 2, 2, 1);

After that, I can make decisions based on the value of the systemUp int. Now, it’s entirely possible that I’m doing this wrong, all I can say is that it works for me now, and it didn’t before.

June 15, 2009 - 2 minute read - cocoa programming


Last summer I decided to dive into programming and give it everything I’ve got. For months, I would get up at 5 and pour through the Hillgass book, every page, every challenge. I’d revisit it at night, after the kids were in bed, and code till I couldn’t stay awake any more. I finished the book, and started coding my first real application. It was then that I found out how very little reading one book gave you. Hillegass says he gives you 80%, I’m thinking it’s more like 50%, tops. I reached out to the Cocoa Dev mailing list for help, and eventually even went to a CocoaHeads meeting with the local chapter. Meeting some “real” developers, I despaired. There was far, far too much that I didn’t know, I felt that it would take me an entire lifetime to learn what I needed to know. I gave up, wrote Goodbye Cocoa, and focused on something else.

January 24, 2009 - 5 minute read - programming cocoa

Goodbye Cocoa

Some times, things come easy to me. I’d like to think that I’m somewhat blessed in that way, especially when it comes to various forms of technology. Back in the Navy, I found I had a knack for telecommunications, and I found that I could grasp the flow of the circuits through various media easily. I nurtured this technological edge, and turned it into a career as a systems administrator. It meant lots of long nights and many mistakes along the way, but it was fun, I enjoyed it. Like I said, some things come easy… but some things just don’t. For example, I have no mental capacity for sports. I enjoy playing every now and again, but I can’t keep track of who’s who and what’s what in this professional team or that college team. It just doesn’t come easy to me.

September 19, 2008 - 5 minute read - programming cocoa culture