Archive for category Tips

Preventing a goto fail (part 2)

I’ve been interviewing candidates lately, which has made me think about everyday things in terms of screening/interviewing questions. Perhaps then a good question for an iOS developer is “How would you prevent a goto-fail situation?”.

Of course, “braces” comes up first, and compiler options may come up second, so let’s change that to “Aside from braces and compiler settings, how would you prevent a goto-fail situation?”.

Over the last few days, I’ve been reversing my role to think how I would answer that from an interviewer.  The idea that occurs to me the most boils down to “defensive coding” or “best practices and standards”. Now that’s way too vague.  As an interviewer I would ask for details.  I’m sure any practiced interviewer would.

For me, the biggest problem with the goto-fail code is the assumption of success until failure throughout the instructions. In critical code, it is better to assume failure until success is specifically reached.  Read the rest of this entry »

NSTimer Out of Sync with Device Clock?

I encountered this puzzle recently:  How does a 60-second, repeating, NSTimer drift way out of sync with the iPhone’s system clock?  The timer was created with a fireDate that was on the even minute with the clock.  It fires at 11:02:00 AM and 11:03:00 AM, etc.  But users report the timer firing at 1:23:30 PM for example.

(And we are not talking about timers not firing because the run loop mode changed temporarily.)

It turns out that the clue is the word “iPhone”. The NSTimer does not drift from the system clock, the system clock drifts from the NSTimer.  The iPhone can have its clock adjusted during the day by the cellular service, especially if the phone goes out of service and comes back. (Changing locations to a different time zone probably triggers it too.)

You can make it happen by just setting the device clock manually.  When you pic a new time, it jumps to the hour and minute chosen, but with zero seconds.  The iOS honors the repeat rate from the last firing and adjusts the fireDate accordingly.

So if you need to stay tuned to the clock, you’ll need to update the fireDate on the NSTimer when you receive the significant time update notification.

Tags:

Waking up Faster

Thanks to Erv Walter for a great blog tip that has my MacBook waking much faster: “Fixing” Slow Wake for MacBook Pro W/ Retina Display

Now my MacBook is wakes very fast when I open the lid.  It took 5 or 10 seconds with the factory settings.

Favorite Quotes 6

“The only thing you can safely assume is that it is unsafe to assume anything.” – Walt Sellers

I recently wrote this while discussing things with a colleague.  Eric Rodriguez-Diaz long ago taught me to challenge my assumptions. I now believe that bad assumptions are a large part of most of the bugs in code.

Tags: ,

XCode 4 Column-Wise Copy-Paste Changed – Update

By accident today, I found that the built-in application TextEdit still supports column-wise copy-paste operations the way I liked them in old versions of Xcode.

I had copied a column of numbers from Xcode and pasted it into a document assuming that TextEdit would just paste it in linearly and I would fix up the format afterward.

SURPRISE!  It pasted in columnar fashion just like Xcode once did.  It made short work of my editing.

A quick test showed that I can hold the option key and copy in columnar fashion as well.

Neither Xcode nor TextWrangler can paste this way.

TextEdit just got more valuable to me for doing work.

My previous blog post on this matter.

Tags:

Xcode 4.3.2 pains and tips 1

So far, XCode 4.3.2 has been irritating.  It crashes far too often.  But here is some of what I’ve learned:

Get a funny response from copy and paste in Xcode? Strange response from Xcode from undo?  Did the change not appear in Xcode?  Did lines disappear from Xcode?

These kinds of things usually indicate that a crash will be happening soon.

Sometimes I can recover by changing to another file, then changing back. This does seem to help keep Xcode running.

My editing habits probably contributed a little. I tend to scroll around, then use undo-redo in quick succession as a way to go back to where I was in the file.  Usually this was fine in previous versions, but Xcode 4.3.2 seems to crash a lot right after I do this.

 

Tags:

Finding Xcode’s Pre-defined Macros for iOS Devices

I regret not making better notes about exactly why I was looking for a full list of the pre-defined macros Apple made available for iOS development.  I usually like starting an entry talking about why I was trying to solve a particular problem.  While I made a note to write up what I found, I did not note why I needed it at the time.  Assuming you are reading this because you need or might need such a thing, I’ll write on.

Some of the pre-defined macros are published in Apple’s documentation, but not all.  (Well, as far as I remember anyway.)  I feel the most confident that I didn’t miss one that could solve a problem when I get the list from the compiler itself.

While searching the internet I found instructions to use

I changed ‘i386’ to ‘armv6’ and ‘armv7’ but that failed on my setup.  I don’t really know if I messed something up in the /Developer folder or if this line just generally won’t work for ARM.

The error message mentioned a missing file and after finding it, I changed the above command to this:

For Xcode 3.2.5:

For Xcode 4.2.1

Change the “armv6” to “armv7” and vice-versa as needed.

Tags: , , , , ,

Fix to Symbolicate System Symbols in iOS 5.0.1 (9A405) Crash Logs

I found this one many weeks back and had it in my to-do list for the blog.  Now that 5.1 is out, I feel guilty I didn’t write it up sooner.  But then, my day job is keeping me very busy.

I had a long period where I could not fully symbolicate crash logs that were made by iOS 5.0.1 devices.  The symbols of my app would be symbolicated, but the system symbols of the device would not.  I was especially frustrated because a coworker with the exact same version of XCode could symbolicate those system symbols with no problem.  Neither of us knew why.

After a huge amount of searching with Google and reading items on StackOverflow.com,  I finally found a note saying the symbols in the iPhone 4S were corrupted somehow and they should be replaced with symbols from another device.  I don’t know if there was a problem with all the iPhone 4S devices, or just some of them or just early ones.

As much as I tried to do this,  I still could not symbolicate properly.  I triple-searched my computer for all copies of symbols for 5.0.1 (9A405) and removed them.  (You can compress them into .zip files if you want to keep them just in case.)

What I needed to know was to look in ~/Library/Developer/Xcode/iOS DeviceSupport   Xcode 4.2 had been putting device symbol information in there.  Once I got rid of that folder, and attached a device, XCode pulled a new copy of the symbols and symbolication worked like a charm.

Top top it all off,  something about the symbolication script in XCode 4.2 works better than any of the previous symbolication scripts, either from Apple or from any developer site.  While symbolication inside XCode can be horribly slow, it does work pretty well.

Hope that helps

Tags: , ,

XCode 4 Column-Wise Copy-Paste Changed

One of the strangely useful features of XCode 3 and 4 is the column-wise copy-and-paste.  But a change in XCode 4 takes away column-pasting.

Not seen this before?  Just hold the option-key while you drag a selection in XCode 3 or 4.  The text cursor will be replaced with a “+” and you can select columns of text right out of the middle of a document. (It helps if the text has vertically-oriented columns.)  It made me chuckle the first time I used it to select a column of tabs and paste them into the middle of a bunch of declarations to move them over all at once.

Pasting in a column required adjustment in XCode 3.  It would paste in the same vertical fashion as the copy, so it was easy to write over quite a bit if you weren’t careful with giving yourself space.  But then that made it interesting too.  I copied a column of member variables and pasted them all at the ends of a series of @property directives in one shot.  The same for the series of @synthesize directives.

In XCode 4, while you can copy a column, pasting it is essentially the same as having copied from any other text. Pasting does not happen in columns.

Admittedly, I did convert my columns to regular text pasting with a quick paste and re-copy in an empty file once in a while because that is what was needed.

Still,  I think I’ll miss the ability to paste in a column.

Cheap Graphics Editing for iOS Apps: icons

Rather than focus on totally free, this time I’m talking a paid, but totally worth the money application.

Art Text by BeLight Software is a cheap application that can give you the glossy, 3D icons and text you expect in an iPhone app with fairly little effort. (Apple Mac App Store link: id404180306)

There is no replacement for a graphic artist, but sometimes you need to make things yourself for practical reasons. And this little app can build some nice little icons that you can use (without embarrassment.)

I’m sorry that I don’t have much time to finish this post, so I’m resorting to some shorthand to list the things I like about this app for iPhone development:

  • You can make your graphics a specific size and fit things to that size.
  • It maintains layers and transparencies nicely.
  • Text and shapes can be filled with color, 3D effects, or images.
  • 3D effects can have multiple light sources. Light sources can be rotated in each item.
  • Shadows and strokes are easy.
  • Can save to PDF for full vector size changes.

Most of all,  with this little app, I can make an icon that looks decent in a few minutes.  If I tried the same thing in Photoshop or Pixelmator, I’d be working for hours to get the same look.