Archive for category iOS Development

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

gcc -arch i386 -dM -E - < /dev/null | sort

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:

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1   -arch armv6 -dM -E - < /dev/null | sort
For Xcode 4.2.1
 /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -arch armv7 -dM -E - < /dev/null | sort
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 – Stopping in the Debugger on NSAssert

I’m not sure if XCode 4 makes this technique unnecessary. Since I originally wrote this, I’ve seen XCode 4.0.2 stop at NSAssert on its own, without me setting this breakpoint. But it may be helpful to someone somehow. So here it is:

Xcode 3: Run Menu -> “Manage Breakpoints”
XCode 4: Go to the breakpoint navigator.

Click the + button at the bottom of the navigator, select “Add Symbolic Breakpoint…” from the contextual menu that appears.

In the “Symbol” box, enter

-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:].

Then click “Done”. (NOTE: this is the default assertion handler. If you are using a custom assertion handler, you probably need to specify a symbol for its object and method.)


Now execution will break immediately on assertion failure. And very usefully, XCode shows the nearest source code of the stack, not the assembly of the assertion handler.

Tags: ,

XCode 4: Conversion Problem

Did you try to build your project in XCode 4 for the first time and get an error that starts with “There is no SDK with the name or path”?

That happened to me recently.  And the path given in the message had nothing to do with SDK’s.  In fact it was an open-source sub-project I was using.

I Googled for the answer, but mostly just found references to posts on how to fix actual SDK path problems.

It turned out that the problem was how XCode 4 looked at the sub-project.  Somehow, XCode 4 had noticed a missing Base SDK, had a static library as the product, and assumed it was a Mac OS X project.

I closed the project and opened the sub-project directly.  I corrected the project settings back to iOS and it built correctly. Closing and going back to the first project, the build now built correctly (with some warnings that I did not recall from XCode 3.)

 

 

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.

Modal View appearing the wrong location?

Is calling presentModalViewController: while a keyboard is visible making your view appear in the wrong place on-screen?

Try sending the message to a different part of the view-controller hierarchy.

I had this problem recently and was getting ready to start hunting down the current first-responder when I lucked into a quicker answer:  change the receiver from the current view controller to the navigation controller. The navigation controller handles getting objects to resign first-repsonder status without any more code from me.

Getting the view dismissed when done is easy too.  Just send the dismiss message to the modal view’s navigationController.

Unsung benefit of App Store: Apple’s Lawyers

I’ve been telling people for a while that one of the unsung benefits of the iTunes App Store is having Apple’s lawyers on your side when a patent troll shows up. (Even the most staunch Microsoft-only shop seems to respect Apple’s lawyers.)

I just pointing out my own supposition based on things like Apple getting the one-click patent rights with Amazon and the endless articles out there that detail the patent troll strategy of getting lots of small companies to settle before taking on bigger companies.

Now, this ZDNet article talks about Apple stepping up to protect its developers from just such patent suits:
http://news.cnet.com/8301-27076_3-20065399-248.html?part=rss&subj=news&tag=2547-1_3-0-20

Of course,  Apple (and any other app store) may have to work harder to get those kinds of broad licenses in the future.

Maybe one day,  Apple, Microsoft, Google and the rest of us will ban together to just buy out patent trolls in bulk and put the patents into a non-profit that charges a reasonable yearly fee to cover the costs of the buyouts and licenses.   (The publicly traded trolls sometimes have a lower market cap than a single lawsuit.)  Somehow that seems more likely than our government doing something about it.

 

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.

Free Graphics Editing for iOS Apps: Text

How much of graphics need can I solve with the free apps that come with the Macintosh?  A challenge I had to take up recently when I did not have my trusty laptop and software.

There are of course free downloadable apps out there, but it should still be worthwhile to find a way.

I needed some text on a clear background.  If needed text on a colored background, it would be easy to make it in TextEdit and just take a screen shot.  An application that can do text and  can save as a PNG file can handle this, but what in the standard Mac apps will do it?  Preview. Apple’s free application for viewing images and PDF files. (Surprised? I was.)

Preview’s menus won’t just make a new file, except to paste what was copied into the clipboard. But you can make files of any size easily.  Just start with a bigger file and crop it down (or resize it).  Or, take a screen shot of something with the Mac’s screen capture and use that.  Command-shift-3 is good, but Command-Shift-4 will let you select any part of the monitor while showing you the resulting size.  It can be helpful to capture and image of the layout you want to put the text into. Then you can fit it right the first time.

If you don’t want to accidentally change your base file, make a copy of it in Finder first. Or use Preview’s “Save As” to set the new file and its location.

To get a clear background in Preview, select all or part of the image and hit the delete key.  Poof! Transparent background.

To get text into your file, start by showing the annotations toolbar. You can:

  • Click the “Annotate” button.
  • Use the menu View -> “Show Annotations Toolbar”
  • Use Tools -> Annotate -> “Add Text”

Drag out a text box and layout your text. You can’t set a shadow on the text, but you can do most other kinds of simple text editing.

CAUTION: when you save, all annotation item become images. Preview doesn’t really do layers even though it will keep separate items until you save (none of the formats saved layer information for me. If it does, please tell me.)

If you need layering in the originals to make changes easier, you’ll need a different program. For Preview, you can make new images by pasting original text from another source.

Opening the Inspector will tell you many things about your file. The right-most tab (pencil icon) will let you set colors and other attributes of the annotation items. There’s more, but perhaps that’s for another post.

Enjoy