PrEV
Thoughts from a NeXTStep Guy on Cocoa Development

iOS SDK Book now in Beta

Dec 14, 2011 by Bill Dudney

Finally shipping! Completely rewritten from the ground up for iOS 5 and Xcode 4.

You can grab your very own copy here.

You can participate in the forums here.

You can report stuff we got wrong here.

Permalink     1 Comment - Add Yours

The NeXT Big Thing

Oct 06, 2011 by Bill Dudney

I've never been much on rules. I finished High School at the very top of the 3rd quartile. I always looked at my time in high school as more or less a tedium to be endured. I floated around a bit after HS wondering what I'd do with my life. I took a couple of classes at a local community college but those teachers were not much more inspiring that my high school teachers.

The second year after graduation a friend convinced me to join him at a 'live in' junior college. I enjoyed my history class, the teacher was crazy. He brought history to life, encouraged me to get into the minds of the people that lived it. But the rest was just more tedium, endured to get a grade that proved I could sit for 3 hrs a week and regurgitate some facts...

Another friend was headed to Texas A&M to study Aero-Space engineering, I loved Star Trek growing up and that sounded about as close as I'd ever get to a warp drive. So I joined him.

I loved the classes, they challenged me to stretch, learn and think deeply about very technical topics. And, it seemed like life building the stuff that got astronauts into space and kept them alive would be pretty cool. And maybe, just maybe I'd have a shot at becoming one of those fortunate few that got into space.

My junior year I joined a group of 3 other students working on keeping planes from going into flutter. Flutter is very bad for planes, it's like the opera singer hitting just the right note, but instead of a wine glass its a dad/son/mother/daughter and a $30M plane being destroyed. The professor was brilliant, the topic deep and difficult and intensely mathematical.

Naturally, we used Mathematica to explore the problem.

To use Mathematica we had to have a beefy computer and our department had just acquired a beautiful new NeXT cube. I instantly fell in love with this computer. Everything about it was new and exciting. After working non-stop on the flutter problem for a couple of months I decided I wanted to go deeper and figure out how to build my own apps.

As the new semester rolled around I had a new infusion of student loan money, that, along with the limit of 2 credit cards gave me the buying power to get my very own NeXT slab.

I had found my calling, that crazy thing that my heart, my intuition knew about. I wanted to build stuff, crazy stuff, beautiful stuff. AeroSpace Engineering and the potential of becoming an astronaut were now secondary.

Thanks Steve for picking up the pieces of what must have felt like a monumental failure and doing something great with it. I owe my entire professional life to you having the courage to keep on keeping on.

I will cary on that legacy by being the absolute best me that I can be. And I will always remember:

Your time is limited, so don't waste it living someone else's life. 
Don't be trapped by dogma — which is living with the results of other people's thinking.
Don't let the noise of others' opinions drown out your own inner voice. 
And most important, have the courage to follow your heart and intuition. 
They somehow already know what you truly want to become. 
Everything else is secondary.

Thank you for staying foolish and staying hungry.

Permalink     1 Comment - Add Yours

Leaving Apple

Jul 01, 2011 by Bill Dudney

As I tweeted a couple of weeks ago, I’m no longer at Apple. It was quite a difficult decision to leave, but as much as I love to help developers, as much fun as it was to plan WWDC, as cool as the evangelism team is, I wanted freedom to do my own thing. There is so much more to say here but it is still jumbled in a bunch of mixed emotions, as I continue to deconstruct stuff I’ll try to write coherent posts about the decision here.

One of the things I wanted to do is help Chris update the iOS SDK Development book. It was a ton of fun to write, it met with some reasonable success and had a great following on the PragProg forums. Given the history of the book it was making me sick that it was languishing with Xcode 3 screen shots and no iOS 4 or iOS 5 content. So I’m super happy to say I’ve signed on as a co-author for the next edition that will include iOS 5 and Xcode 4. I’ll be posting about the book over the upcoming weeks with updates as we approach beta.

I love helping and teaching developers, but I also love to write code that ships. As an evangelist I got to do a bunch of the prior but none of the latter. So I’m also chomping at the bit to get back to my apps, that will have to wait till the book is done. I’ll post about what I learn from converting iOS 2 and iOS 3 apps to iOS 5 as I get started on those transitions. I know most of you have probably already gone through this so I’ll mostly be writing those entries for myself :)

Since I love to teach I really missed being at conferences so I’m super happy to say I’ll be at CocoaConf in August. It’s a great line up of speakers, I wish I was going as an attendee so I could see all the other talks! It would be great to see you there.

Thanks for taking the time to read and I'm really looking forward to getting back into this side of the community!

Permalink     14 Comments - Add Yours

iOSDevCamp 2010

Aug 23, 2010 by Bill Dudney

I will write up the whole weekend but a lot of people wanted to see the demo we did on Sunday so I've made a quick screenshot video showing the two animations that we demo'd on stage at iOSDevCamp.

For those that do not follow me on twitter here is a brief recap. Andrew (my oldest son) and I went to iOSDevCamp last weekend. He won the "Best Upcoming Developer" award for his Unreal Model Viewer iPhone/iPad app, this is a screencast of the demo we gave on Sunday. If you ever have the chance you should make it to one of these, its a ton of fun!

Permalink     2 Comments - Add Yours

1 Infinite Loop Cupertino CA

Jan 25, 2010 by Bill Dudney

I'm very excited to announce that I have in my possession an offer from Apple to fill the position of Application Framework Evangelist. And I'm even more excited to say that I'm going to accept it. It has been a crazy ride getting here, but I'm really glad to have arrived.

Now for the why. Why would I go from Indie to working for the Man? Well in this case the Man is Apple, and I think we can all see the appeal there :) But seriously the thing I really enjoy doing is helping people build stuff for the Mac and iPhone. My favorite Amazon review is 0 to iPhone App in 6 months. I love that review because that person went from nothing to app, that one review made the book worth writing. Not saying the $ wasn't good too, but the real motivator is helping people. I love it.

As I thought about this job it is helping people x10. I don't just get to help the people that follow me on twitter or that buy the book or post to the forum but I get to help everyone doing Mac and iPhone stuff. And that totally rocks!

I feel like there should be a pithy movie quote or song lyric here, all that comes to mind is 'A dweeam wiffin a dweeam' and 'Heading out to San Francisco'. If more come to mind I'll be sure and post them :)

My start date is Feb 15, can't wait!

Permalink     39 Comments - Add Yours

Foto Brisko - First Review!

Jan 11, 2010 by Bill Dudney

The first review of Foto Brisko is up at TUAW.

Permalink     Add A Comment

Foto Brisko - Live!

Jan 06, 2010 by Bill Dudney

Well its finally here! Foto Brisko is finally live in the store!

Permalink     6 Comments - Add Yours

Foto Brisko - almost there!

Dec 04, 2009 by Bill Dudney

I have been extremely quite on my blog lately, partly because I'm posting a bunch on twitter but also partly because I've been scrambling to finish my latest iPhone app.

It has been a great time, and a mad scramble. I was honored to make the first cut with the Apps Fire people. I've embedded the 50 second preview here. If you are so inclined please go here and up-vote the app.

Permalink     5 Comments - Add Yours

Game Kit Preso - Voices That Matter:iPhone

Oct 17, 2009 by Bill Dudney

Voices that Matter talk finished, was great fun. Here are the slides.

The source code for Disk Smash (the demo code from the talk) is available here

Permalink     Add A Comment

Boulder Developer Day - Core Animation

Oct 12, 2009 by Bill Dudney

Here is my very brief introduction to Core Animation on the iPhone.

And you can find the source here; Photo Search source code.

Permalink     Add A Comment

Custom Views During Text Entry

Oct 05, 2009 by Bill Dudney

The app I'm currently working on requires a custom view to be taking all the visible are between the search bar and the keyboard. So I spent a bit of time experimenting and came up with this little recipe that might be useful to you.

The first thing you need to do is register to be notified when the keyboard becomes active. This code makes that happen.

  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillShow:) 
                                               name:UIKeyboardWillShowNotification
                                             object:nil];

I placed this code into my view controller's viewDidLoad method but a different location might be more appropriate for you.

Then in my keyboardWillShow: method I calculate the visible space and make that the frame of my overlay view. Like this;

- (void)keyboardWillShow:(NSNotification *)notification {
  if(nil != self.view.window){
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
    CGRect keyboardBounds = [[[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
    CGRect searchBounds = [self.searchBar bounds];
    CGFloat height = CGRectGetHeight(appFrame) - CGRectGetHeight(keyboardBounds) - CGRectGetHeight(searchBounds);
    CGRect visibleBounds = CGRectMake(CGRectGetMinX(appFrame), 
                                      CGRectGetMinY(appFrame) + CGRectGetHeight(searchBounds),
                                      CGRectGetWidth(appFrame), 
                                      height);
    self.overlay.frame = visibleBounds;
  }
}

This works for me because my overlay view becomes a subview of view controller's view. If your view hierarchy is different you might need to do some different math.

Now with this view in place I can process a single tap as a cancel. You could do just about anything here though.

Happy coding!

Permalink     3 Comments - Add Yours

iPhone SDK Development In Print (W00T!)

Oct 01, 2009 by Bill Dudney

If you follow me on twitter you've already hear. But I'm still so excited that I can't keep from posting here. The iPhone SDK book is finally in print. Yippy!

Permalink     1 Comment - Add Yours

360iDev Denver 2009 MapKit Presentation

Sep 30, 2009 by Bill Dudney

The presentation I gave today at 360iDev is now online here;

The sample code is also available.

Permalink     2 Comments - Add Yours

Inversion of Control

Sep 11, 2009 by Bill Dudney

I've been in the Cocoa/CocoaTouch world now full time now for more than two years. But I still remember bits and pieces of my former life in the Java IT world. One of the hot topics there (or it was hot 2 years ago) was Spring.

Spring was such a big thing because it relieved Java programmers from the tedious complex nature of J2EE programming and made it fun and simple again to write apps. The main idea behind Spring was coined 'Inversion of Control'. The term came from the fact that the controller class you were writing did not need to know where its JDBC (database stuff) connection came from, instead it just relied on the connection being set by someone else. In other words the controller gave up control of knowing everything about its dependent objects at all times for a much simpler programming model.

It struck me during the last studio that Daniel and I were teaching that Interface Builder and the loading mechanism for nib files is a lot like the Spring module loading stuff. Sure you give up control and knowing everything all the time, but what you get is priceless.

One example is the files owner. I don't remember the exact term used in Spring but you can declare a bean in a spring config file that says 'I represent an object that will be supplied at load time' and then proceed to add configuration for that bean despite the fact that the object is created elsewhere. Before this file is loaded none of the configuration represented there has been performed, despite the object being created. When you need the configuration, you load the spring file and bada-boom, bada-bing you have your configuration.

In IB you create a nib file and set the file's owner to some class of your making. You connect the view, wire up some actions to buttons or other controls etc. But none of that configuration is available until the nib file is loaded. Consider a nib file whose file's owner is one of your view controllers, you create the instance of the VC in a parent nib file. When that nib is loaded the VC is created, but it does not have a view or the target/action connections specified in the child nib file. However when it's asked for it's view and the nib file is loaded all those connections are made.

The much simplified bunch of code that you get is one thing, but even better is that you get a simplified programming model. True that much of the simplified programming model comes from the way that Cocoa Touch works. But, most of the design patterns used in Cocoa Touch are influenced by IB (and vice-versa).

My hope is that if you are coming from Java and you are familiar with Spring that this write-up will help you to get a little further along in your understanding of IB and how it works. Just like spring folks would never dream of writing an IT app in the old style (J2EE 2.0 old style) because of its complexity, I would never dream of writing an iPhone or Mac app without using IB, why would I poke myself in the forehead with a sharp stick :)

Give up your need for control and be happy!

Permalink     2 Comments - Add Yours

Core Data Code Generation

Sep 08, 2009 by Bill Dudney

When building Core Data applications you can choose to use the NSManagedObject class for most of your entities, but from time to time you need to have a custom class to add custom code to. You might want to do lazy initialization of transient attributes, validation of the instance, or any number of other things you need to do with instances of your Core Data classes (they are Objective-C objects after all).

When you start adding custom code to your classes maintenance becomes a hassle, when you add an attribute you can either manually keep your custom classes in sync or regenerate the code. When you regenerate Xcode kindly keeps the old version of your code (if you click the right button) but you have to manually merge your custom code back into the freshly generated code. The manual merge is almost always a piece of cake but it can still be a time sink to have to do that with each new attribute you add. So I use categories to manage my custom code and make the regeneration of classes a snap.

Categories, for those that don't know, are a way to extend existing classes in the Objective-C runtime. A category can be thought of as a bag of methods that are added to a class when the category is loaded (of course the real technical details are a bit more complex). So I put all my custom code into a category that I typically call 'Custom' in a separate files named ClassName+Custom.h and ClassName+Custom.m. That way when the main class is regenerated I don't have to manually merge the custom code back into my generated code.

Here is the interface for a Movie class that we could persist via Core Data.

#import 
@interface Movie : NSManagedObject {
}

@property(nonatomic, retain)NSString *name;

@end

And here is the 'Custom' category interface for the Movie class.

#import "Movie.h"

@interface Movie (Custom)
- (void)play;
@end

What this is saying to the compiler is that we have a new method 'play' that will be added to the Movie class at runtime when this category is loaded. If you import Movie+Custom.h instead of Movie.h you will be able to use this play method without compiler warnings.

The implementation of the Movie class is simple, its just got the @dynamic statement in the implementation block. The category implementation looks like this.

#import "Movie+Custom.h"

@implementation Movie (Custom)

- (void)play {
  NSLog(@"playing %@", self.name);
}

@end

This implementation block provides the code for the play method and is what gets added to the Movie class at runtime.

You have to, of course, be careful with Categories because you can get into trouble. For example, what happens if you replace a method on the main class with a method in the category? I'll leave that between you and the docs. But don't be afraid of this sort of straightforward usage of categories, it can make your life much easier.

Hope this helps your usage of Core Data to be even better.

Permalink     2 Comments - Add Yours