Archives for category: iOS SDK

In a much needed area of training for Xcode/Mac/iOS developers, iDeveloperTV and Graham Lee have put together a modestly-priced course on Unit Testing and TDD.

Unit Testing with Xcode

In this course Scotty and Graham Lee help you to not only understand the mechanics of unit testing in Xcode but also show you how you might design your code to be more testable. By working through a number of examples you will initially learn how to set up unit tests within Xcode 4 and perform basic unit testing before moving on to discover how you can test parts of your code that you previously might have thought were not possible to unit test such as code that uses singletons, networks, tableviews, user defaults and even core data. All the code we look at during the course in included so you can follow along and make sure you fully grasp and understand each aspect of what is being taught. The course ends with a general discussion of unit testing principles and examines how adopting a test driven approach to your development could end up saving you time and help you to produce more robust applications The course is suitable for both OS X and iOS developers

Good tip from iOS Developer Tips for using the “Related Files” button in the upper left corner of your code window (right next to the Back/Forward navigation buttons):

Xcode 4 : Related Files List

With Xcode 4 you can quickly access an assortment of files related to your project through the Related Files option in the Jump Bar.

 

This sounds like it could really be a problem for developers who store anything but truly temporary data in the Caches or tmp directory…

Cleaning… – Marco.org

Every iOS app has its own “home” directory where it can store files. Every file and directory that an app puts there, except anything in a Caches or tmp directory, gets backed up when you sync your device to iTunes.

Prior to iOS 5, the system never deleted the contents of Caches and tmp, so they were safe places for apps to put data that should always be available but could be redownloaded if the user did a complete restore or otherwise lost all data, and therefore shouldn’t be taking up space in backups and slowing down syncs.

In iOS 5, since iCloud backups are now possible, Apple has started cracking down on apps that store too much in any backed-up directory, such as Documents.

Instapaper has stored its downloaded articles in Caches for years, since I didn’t want to slow down iTunes syncing for my customers or enlarge their backups unnecessarily, and full restores don’t happen often enough for it to be a problem for most people. This new policy now locks me into using Caches: I no longer have a choice.

But in iOS 5, there’s an important change: Caches and tmp — the only two directories that aren’t backed up — are “cleaned” out when the device is low on space.

Nice rundown on Xcode 4 Code Snippets:

Xcode 4 Code Snippets – Speed of Light

Xcode 4 Code Snippets   ? Perhaps my favourite feature of Xcode 4 is the Code Snippets feature. It allows you to use common bits quickly in your code, instead of requiring you retype them over and over again.

Nice little introductory tutorial for using UIActionSheets in iOS.

Simple Menus and Messages with UIActionSheet

If you need to create a quick menu or present a user with a short message, you may want to consider a UIActionSheet as an option. This control will slide up from the bottom of the screen, and offers a number of easily configurable options.

For the longest time, to perform a search in Xcode I would take a standard, yet uninformed, approach by selecting a desired region in my code, copy it to the clipboard with Command-C and then perform a Command-Shift-F to find all instances of the search in my project. Cool.

Then after a while I actually looked at the bottom of the Edit –> Find menu. At the end of the list there is an item entitled “Use Selection for Find” and its shortcut is Command-E.

The beauty of this command is that it puts the search term in a separate location preserving the contents of your clipboard.

This is particularly nice since now I can have text in my clipboard and still perform a search – a bit like having your cake and eating it too.

Thanks Xcode Team!

Recently, I was having an issue I was having with subviews added to my UIButton objects that I was customizing. The buttons would behave fine if they were standard rounded rect buttons, but the moment I added a UIView and some UILabels to it, the taps stopped responding.

But I was able to resolve it, thanks to the tip provided here:

iPhone: Subviews in UIButtons block the touch, unless…

The solution boils down to something very simple and it makes sense when you think about it, but at first it seems strange:

  • All you need to do is set userInteractionEnabled and exclusiveTouch to NO on the items that you want to add as subviews to your UIButton (and don’t set those properties to NO for the UIButton itself).

Once you turn off user interaction and exclusive touch properties on the subviews, your events will be sent to the underlying button (or at least that’s how I like to think of it happening…).

I initially read the post wrong and set them to YES and couldn’t figure out why it wasn’t working. Then I went back and looked at the comments, which pointed out where I went wrong.

Hope this helps!

///eks

Handy tip of the day:

To scroll to the top of a UITextView, simply use the following method:

[textView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];

Hope it helps!

For a project I’m working on, I needed to know how to monitor the input level using AVAudioRecorder. Thankfully, this post from Dan Grigsby was very helpful in setting up the polling mechanism (though you might not guess it from the title!):

Tutorial: Detecting When A User Blows Into The Mic

If, a couple of years back, you’d told me that people would expect to be able to shake their phone or blow into the mic to make something happen I would have laughed. And here we are.

Detecting a shake gesture is straightforward, all the more so in 3.0 with the introduction of motion events.

Detecting when a user blows into the microphone is a bit more difficult. In this tutorial we’ll create a simple simple single-view app that writes a log message to the console when a user blows into the mic.

Thanks, Dan!

I ran into this one yesterday since I needed to create a delegate method that took a couple arguments, and it wasn’t clear to me what the correct syntax was when one had more than one. So thanks to Adam Rosenfield on Stackoverflow for this one (he helped clear up another issue I was researching a couple of weeks ago but I failed to blog about that one I think…).

Selectors in Objective C – Stack Overflow:

You have to be very careful about the method names. In this case, the method name is just “lowercaseString”, not “lowercaseString:” (note the absence of the colon). That’s why you’re getting NO returned, because NSString objects respond to the lowercaseString message but not the lowercaseString: message.

How do you know when to add a colon? You add a colon to the message name if you would add a colon when calling it, which happens if it takes one argument. If it takes zero arguments (as is the case with lowercaseString), then there is no colon. If it takes more than one argument, you have to add the extra argument names along with their colons, as in compare:options:range:locale:. You can also look at the documentation and note the presence or absence of a trailing colon.