UIDatePicker Height Inconsistency at Runtime [#iOSDev, #SwiftLang]

Apple needs to fix this one.

There is an inconsistency in the way that the UIDatePicker is rendered in Storyboards in Xcode vs. their rendering at runtime. This problem set me back longer than it should have this morning, since its effect was tricky to diagnose. The basic consequence of this was that the custom UIButton I had attached to the top of the date picker (inside a UIView) was not receiving taps and for the life of me I couldn’t figure out why…

First, to diagnose the problem, I used this tip to get the UIView recursiveDescription method working in my Swift project, and I was able to get a dump of the view hierarchy. From that, I could tell that the UIView I had created as a container was at a Y value of -54, and was therefore outside the bounds that I had set for the custom view, and was not receiving tap events.

Then I stumbled on this Stack Overflow post by Florian Mielke, which suggested that there is a typo-bug somewhere in Xcode or iOS in the rendering of UIDatePicker in a Storyboard vs. Runtime:

iphone – iOS 7 UIDatePicker height inconsistency? – Stack Overflow

“I can confirm that using UI(Date)Picker in storyboards has a different height (162.0) than in “reality” (216.0). Therefore you have to adjust the space to container view to fit that ‘real’ date picker height or try to solve it using auto-layout.”

Reconciling that with the output from recursiveDescription totally agreed with this, and once I increased the size of my custom view, taps were once again being received by the Done button!

Unit Testing with Xcode Course from iDeveloperTV and Graham Lee [#iosdev #cocoadev #macdev #tdd]

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

Xcode 4 Tip from iOS Developer Tips: Related Files List [@iosdevtips, #iosdev]

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.

 

iOS 5 now cleaning out Caches and tmp directories – could pose a real problem for app developers [#iosdev, #iOS5, @marcoarment]

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.

iOS Tutorial from @iosdevtips: Simple Menus and Messages with UIActionSheet (#iosdev)

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.

Xcode Tip: Command-E [#iosdev #xcode]

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!

#iOSDev Tip: Unblock events caused when adding subviews to your UIButtons

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

Monitoring AVAudioRecorder Input on iOS

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!