The Johnson Blog

Ramblings of a geek with a few hobbies…

  • Funny Faces

    Last night I got out the ring flash and asked David if he could make some funny faces for me.  Here’s the result!

    Update: more photos in the gallery.

  • Weekend in St. Louis

    This past Wednesday I decided it would be fun for us to get out of town for the weekend, so away to St. Louis (Aint Looooois as David says) we went.  Jay and Katherine also came along with us, which was nice since we haven’t seen them too often of late.

    We left Springfield Friday evening after work and got to the hotel in downtown St. Louis right around 8pm.  David crashed quickly and we played a card game I was terrible at until it was time to get some sleep. 

    After getting some breakfast on Saturday morning we headed over to the City Museum.  Neither Ana or I had ever been there before but have heard lots of great things about it.  Now all I have to say is that we all had a blast and I can’t wait to get back there.  So much fun!

    After the museum we had lunch at the delicious Schlafly Tap Room and headed back for a much needed nap.  We wrapped the day up with dinner at the Galleria, an interesting search for a Walgreens, and more card games. 

    Today we went up to the top of the Arch and had more good food for lunch before the drive back to Springfield.  David had a blast and it was a nice getaway for all of us.

    Photos in the gallery.

  • iPhone Objective-C for the C# Developer

    If you’re a C# developer making your first foray into the land of iPhone and Objective-C programming, you probably have a question or two.  I recently started working in earnest on an iPhone app, so I figured I would write down some of the tips I’ve picked up thus far.

    Here they are in no particular order.  No particular level importance.  Just some things that I had to learn and which may help you as well.

    Objective-C

    • It’s a strict super-set of C, so straight C code is compilable in Objective-C
    • Back to the old header and implementation files (.h and .m, respectively)
    • There are two types of methods in classes, instance and class methods.  Denoted by a prepended “+” or “-” on the method prototype.  Class methods are just like static.
    • All methods are public(!).  That’s right, read that again.  There’s a hack/technique having to do with Objective-C categories to help hide them in the IDE, but they are still callable.
    • NSObject is System.Object.
    • No garbage collection on the iPhone, there is  reference counting instead.  More on this later.
    • What we typically think of as constructors are “init” methods.  Destructors are “dealloc”.  There’s nothing special about these methods, it’s just convention.
    • Properties are denoted with @property lines in the header file.  Corresponding @synthesize statements in the implementation file generate the property code.  Special directives in the @property declaration determine the specifics of the implementation (nonatomic, retain, etc.).
    • Use #import over #include – it prevents a file from being indrectly #included more than once.
    • What .Net calls Interfaces are called Protocols in Objective-C.
    • this pointer is called self
    • base is super
    • Methods are referred to as selectors.  Calling a method is referred to as sending a message to an object.
    • Message sending syntax is [recipient method] or [recipient method:paramvalue] or [recipient method:paramValue param2name:param2value]
    • @selector() is for specifying what are essentially delegates.
    • id datatype is basically NSObject*
    • There are C strings and there are NSStrings.  C string constants are defined like “something”, NSString constants are defined like @”something”
    • [[someClass alloc] init] is the typical instantiation pattern. Sometimes there are parameters, as in [[someClass alloc] initWithValue:someValue].   Sometimes you can just call a factory method on the class as in [someClass someClassFromData:data].  The only real difference has to do with the reference counting of the returned object (again, by convention).
    • Events are achieved by what they call delegation – registering/attaching an object that adheres to a protocol (interface) to subscribe to events (called Actions).
    • No namespaces, but there are categories which I haven’t bothered touching.

    Reference Counting

    • NSObject implements reference counting.
    • Calling alloc or copy sets the reference count to 1.
    • To decrement the reference count, call release.
    • When the reference count hits 0, NSObject calls dealloc.  NEVER call dealloc yourself.
    • Call retain to increment the ref count.  Basically, if you need to keep hold of an object for longer than the duration of one message event cycle (event handler), call retain.    You don’t need to call retain on an object that you directly created with an alloc or copy call – NSObject called retain for you.
    • Calling release one too many times is bad – dealloc will end up getting called twice and cause a crash. 
    • There is an AutoReleasePool and the ability to call autorelease on NSObject.
    • When you call autorelease, the release  call gets posponed/scheduled in the AutoReleasePool.  This is used when a function needs to return a newly created object to the caller.  If it doesn’t call release, the ref count will be incorrect.  If it does call release, it will immediately be deallocated.    Calling autorelease will give the caller time to call retain to take ownership.
    • When does the autoreleasepool finally call release?  The pool gets drained at the end of every message pump loop, cleaning up any autoreleased objects.
    • So, so summarize… if you call alloc or copy, you need to call release.  If you use a class factory method and need to keep the object around, call retain and be sure to have a matching release later.

    Interface Builder

    • I have yet to see why Apple developers fall all over themselves about Interface Builder.  No comparison to Visual Studio.
    • Interface Builder writes to .xib files (which for some unknown reason are called Nib files).
    • It parses your header files for IBAction and IBOutlet on declarations to determine event handlers and variables for interface elements respectively.
    • IBAction is a #define for void.
    • IBOutlet is a #define for blank.
    • Just saving the .h file is sufficient for IB to reparse and pickup the changes.

    Ok, I’m tired of typing now.  That ended up a little longer than I intended but I hope it helps you to get up to speed.

  • Hammering!

    This morning we were at Lowes and ran into the bi-monthly kids’ workshop in progress.  They were putting together a smal tic-tac-toe toy and David was instantly hooked.  Since they were wrapping up, we bought the smallest hammer we could find for him and took one of the kits home with us.

    Later in the day after his nap, we got to work in the basement.

    IMG_5203

    IMG_5207

    Here’s to David’s first building project!  More photos in the gallery.

  • Back to 2 Cats

    The Johnson household is back to two cats.  Today we went to Sangamon County Animal Control in hopes of finding a suitable kitten for our home, and brought home a fun little energetic boy. 

    IMG_4939

    David immediately started calling him Bottles for reasons unknown to us, so we figured we’d try that out as a name.  Several hours later we decided Bottles just wasn’t working out, so we instead have ended up with Faraday.  Dozer and Faraday.   Works well.

    More photos available in the gallery.

  • Noreve Leather Case for Kindle DX

    One of my Christmas gifts from Ana was delivered today, my new Noreve Kindle DX Tradition leather case.  And it looks and feels great.

    IMG_4920

    Unlike many of the Kindle 2 and Kindle DX cases out on the market, Noreve has avoided the terrible hinge system for this case.  Thank goodness, because the Amazon case with the hinge caused our DX to crack (eventually replaced by Amazon).  Instead, it uses sturdy, leather-covered tabs to keep the kindle firmly in place in the case without worry of scratching or otherwise damaging the device.  You just slide the Kindle in from the left and into place beneath the “tabs”.  Unlike in the Amazon case, the Kindle is going nowhere in this thing.

    IMG_4900

    The case is padded quite nicely, has a stylish texture, and a good magnetic closure.

    IMG_4887

    One concern I had before receiving it today was that it may be too bulky, but surprisingly even with it’s padded feel it isn’t noticeably bulkier than the stock Amazon one.   The front cover can comfortably be folded back and out of the way while reading, and unlike Amazon’s case you don’t have to worry about opening it from the wrong side (which can lead to those cracks!).

    IMG_4915

    I spent a lot of time looking for a good case for the DX, and ended up with a great one.   While it’s a bit more expensive than competitors’, every indication thus far is that it’s going to be worth every penny.

    For more photos of the case, check the gallery.

  • Painting Project

    This weekend I built the second step stool for David, this one for an upstairs bathroom. 

    I also got both sanded, primed, and covered in a coat or two of paint.   One red, one white.   The white was so we could turn David loose on it to make it his own.  With Mom’s help, 30 minutes, and a few tubes of paint, he deemed it complete.  There is no mistaking it, it’s his!

    IMG_4797

    As always, Mr. Serious:

    IMG_4769

    Here’s our work, side-by-side. I’m happy with how they turned out and they should last beyond their need. 

    IMG_4864

    So that’s what we did this afternoon; it was fun and provided a nice little diversion on this cold, cold January Sunday.  If you’d like to see a few more photos of David’s artistic process, they’re in the photo gallery.

  • New Years Eve

    Here it is New Year’s Eve and David has come down with something.  He’s just spending the day taking in medicine and an Imagination Movers marathon from the couch.

    IMG_4737

    A far cry from the active little guy that was two days ago.

    IMG_4720

  • Christmas Preparations

    David spent this Christmas Eve morning helping Mom make Santa’s cookies, and after a quick nap he’ll get to decorate them too.

    IMG_4365

    He is pretty excited, even if he isn’t quite sure why.  On more than one occasion he has run up to me saying “It’s Christmas!”

    This is going to be fun 🙂

    Update: decorating has begun!

    IMG_4399

  • 2 Years Ago Today

    2 years ago today, Ana and I were sitting in a hospital room with our brand new son, David.

    IMG_3765

    That photo is the result of asking him to smile big for me tonight.  Just wonderful, the little ham.

    Happy Birthday, David.  You sure make it fun!