Posts tagged mistakes
UIView Manipulation Made Easier with a Category
Jul 27th
I was watching a presentation recently where the presenter showed the header for a category that he had added to UIView to make his life a little easier. The point of the talk did not center around the category so I never saw much more than the header, but that was all I needed to recreate it for my use. Here’s the header:
#import <uikit/UIKit.h> @interface UIView (MFAdditions) - (id) initWithParent:(UIView *)parent; + (id) viewWithParent:(UIView *)parent; // Position of the top-left corner in superview's coordinates @property CGPoint position; @property CGFloat x; @property CGFloat y; // Setting size keeps the position (top-left corner) constant @property CGSize size; @property CGFloat width; @property CGFloat height; @end
As you can see there isn’t a whole lot to this category, but if you’re doing a lot of view manipulation the benefits of it will rapidly become clear. There was one sticky wicket that I hit when implementing this class and it centers around this method:
+ (id) viewWithParent:(UIView *)parent;
When I first implemented this method I wrote it like so:
+ (id) viewWithParent:(UIView *)parent { return [[[UIView alloc] initWithParent:parent] autorelease]; }
This was all well and good as long as the only class that I was creating was a UIView, but I ran into trouble when I started creating UIImageViews. Instantiating new UIImageViews worked fine, but as soon as I called a UIImageView-specific method the app would crash:
*** -[UIView setImage:]: unrecognized selector sent to instance 0xd1b350
I struggled with the answer to this one for a while and it wasn’t until I presented my problem to the local CocoaHeads group did I get it all figured out. Here’s the correct way to write this method:
+ (id) viewWithParent:(UIView *)parent { return [[[self alloc] initWithParent:parent] autorelease]; }
By calling self instead of strongly typing the returned object as a UIView the class would dynamically determine the correct type at runtime.
You can download this category here: UIViewAdditions
Well That Didn't Take Long
Jun 29th
As you can see we are now flying under a new banner: Core Fruition! In less than two hours from my last post I had the answer to my naming quandary from Paul Goracke, and I can’t thank him enough.
When I saw Paul’s suggestion my first thought was, “That’s an awesome name!”. My second thought was, “That sounds really close to another popular Cocoa site…” Not wanting to step on any toes, I decided to throw the name into some focus testing, asking a bunch of high ranking folks for their gut reaction. Here are the results:
Mickey Roberson: “That’s not bad“
Bill Dudney: “Frution is too ‘hard to read’, but not gut reaction is I like it … cool name“
Danny Greg: “rip off of core intuition, other then that – nice“
Jeff LaMarche: “I like it.“
Dave Verwer: “I like Core Fruition“
Brent Watson: “I like it“
Marcus Zarra: “I like it. Makes me think of learning cocoa“
As you can see, most folks liked it with only Danny giving me the reaction I was afraid of, which wasn’t enough to keep me from pulling the trigger. I’d like to thank everyone for submitting names and cool ideas, and especially Paul for hooking me up with a winner. Now, if some intrepid graphic designer would like to hook me up with a sweet logo…
I am Not a Name Thief
Jun 29th
Not intentionally, anyway. First a little back story: When I was trying to decide on a name for this blog I would come up with what I thought was a great name and then plug it into Google to make sure that it wasn’t already taken. Most of the time I would find a blog that already had the same name and move on to a new round of brainstorming. When I arrived at the name “Cocoa Nut” I thought for sure it would be taken. I did a quick search but found no hits for that name having anything to do with programming in the first few pages of search results. I thought, much to my amazement, that I had struck blog naming gold, I couldn’t believe my luck!
Fast forward to last week. I was looking up some show notes on the Mac Developer Network when I noticed the blog roll on the side of the page. Curious if my blog was listed there (I had submitted it to Scotty a while back) I took a quick glance through the list and saw Cocoa Nut sandwiched between Call Me Fishmeal and Cocoa Samurai. I clicked through expecting to be greeted with my blog’s homepage but was instead taken to a different Cocoa Nut.
Astounded, I quickly checked his archives, sure that he had shown up on the scene after me and had not been thorough enough in his search for naming collisions. 2006. His first post was from 2006. My first post was in 2008. I was sunk.
So back to the title of this post: I am not a name thief. I am currently searching for a new moniker for this blog. Yes, I could make the argument that in a fully qualified world his Cocoa Nut and my Cocoa Nut are in completely different namespaces and that they don’t collide, but that’s BS and everyone would know it.
Therefore, if you’d like to suggest a name, please feel free. Otherwise, I will be thinking and Googling until I come up with something that no one else has thought of yet.



