Resolving the ‘setStatusBarHidden:animated:’ is deprecated Warning

I’m working on chapter 6, Subclassing UIView, of iPhone Programming
by Joe Conway and Aaron Hillegass1 to learn iOS programming. There’s a deprecated method in the code for hiding the status bar in the Hypnosister app. Xcode 4 generates a warning that UIApplication setStatusBarHidden:animated: is deprecated.

One of the ways I make sure I’m understanding the material rather than just typing in examples is to chase down issues like this. Here’s how I did it: I selected the method, setStatusBarHidden, in the code and used the “Jump to Definition” feature (control-command-D or Navigate|Jump to Definition on the menu). That brought up the source for the method. The comment at the end told me to use -setStatusBarHidden:withAnimation:. Using the code completion feature I changed the original line:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];


[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:

Now, that’s not complete because the message that should follow withAnimation: isn’t there and I didn’t know what to send. So I selected the signature, setStatusBarHidden:YES withAnimation:, and used “Jump to Definition” again. That source told me that withAnimation: expects a UIStatusBarAnimation. I thought, “Great. I’m making progress, but is that an enum or what?” To get the answer, I selected UIStatusBarAnimation in that source and again used “Jump to Definition” where I learned that it is an enum that can be UIStatusBarAnimationNone, UIStatusBarAnimationFade, or UIStatusBarAnimationSlide. The first one best matched the original intent of animated:NO so I entered it in HypnosisterAppDelegate2 resulting in the following line of working code:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

Now I’m headed back to the iPhone Programming
ebook to start working on the next challenge: making the concentric circles appear in assorted colors.

1. I’ll get iOS Programming: The Big Nerd Ranch Guide (2nd Edition) when it’s released.
2. I experimented with UIStatusBarAnimationFade and UIStatusBarAnimationSlide before implementing UIStatusBarAnimationNone; no animation just seemed less interesting. I thought fade was cool, but liked slide best.