Archive for the ‘iOS’ Category

iOS Simulator and Documents folder

Sunday, August 4th, 2013

Note: This only applies to Xcode 5 and earlier. Xcode 6 rather radically changed the location of the app and its associated data folders.

This is geared to the iOS developers or project managers who might be testing builds with the simulator out there…

Recently, my client wanted to check out wow their currently shipping app would look under Apple’s new iOS 7. Since they did not have iOS 7 installed on any of their testing iPads, they wanted to run the latest code base under the simulator. Their app requires some files in the Documents directory to be at useful, so the question of how to populate it with test data came up. Here is the skinny:


When you are developing an application for iOS, I would guess that a majority of the time (except in certain situations) you will be relying on the iOS Simulator (it is actually named “iPhone Simulator”, but it covers all the iDevices, so whatever). If for no other reason than the code-compile-debug cycle is much faster. But what if your application works with external files stored and transferred in and out of the Documents directory?

From here on out, we are going to assume a bit of familiarity with If you are a developer and don’t have experience with Apple’s command line terminal application, we keep it fairly simple, but you really should become familiar with it. Please launch it now. You will find it in /Applications/Utilities/.

Find The Way

So, when Xcode runs your application in the simulator, where does it live? Here:

~/Library/Application Support/iPhone Simulator/<iOS version>/Applications/

Where <iOS version> might be “6.1” or some what ever (well pretend at this date and time we are referring to 6.1, but it would be the same with any version). If we get a directory listing (ls command), we should see something like:

Screen Shot 2013-07-26 at 1.25.54 PM

Here we see 7 different entries, each corresponding to a different application (your listing may have more or less, depending on how many different projects you have going at one time). When the application is launched in the Simulator for the first time (or after a “Reset Contents and Settings…” from within the simulator) Xcode creates and associates an Unique IDentifier (erstwhile known as UID) with which to name the directory for the application bundle and to track the application from within the debugger.

As you might expect, this makes it slightly challenging to find your app. Sometimes, using the ls -l command will give us the additional information we need (namely, date of the creation for the directory), from which we can determine our desired directory.

Screen Shot 2013-08-04 at 7.02.44 PM

Otherwise, we can do:

ls ~/Library/Application Support/iPhone Simulator/6.1/Applications/*

and examine the results to see which contains our application (looking for You should see each of the above directories (with UID naming) plus their contents listed beneath each.

Screen Shot 2013-08-04 at 7.03.56 PM


OK, so now we know our path to our target iOS application. From here on out we’ll use 05EF4BB0-A995-99C1-067752EAD15B as our example UID. The path to this applications’s Documents directory will appear as such:

~/Library/Application Support/iPhone Simulator/6.1/Applications/05EF4BB0-A995-99C1-067752EAD15B/Documents/

Now we’ll employ the services of the Unix command cp (for copy) in the Terminal:
cp -v /path/to/file or files/we/want/copied/* ~/Library/Application Support/iPhone Simulator/6.1/Applications/05EF4BB0-A995-99C1-067752EAD15B/Documents/

Translated this is telling the system: copy all the files in the source directory to our simulator app documents directory. The ‘-v” tells cp to report each file copied, so you can leave this option off if you like.

If you prefer to use the OS X Finder to drag-and-drop copy files, then simply issue the system command

open ~/Library/Application Support/iPhone Simulator/6.1/Applications/05EF4BB0-A995-99C1-067752EAD15B/Documents/

And a new window will be opened with connected to the Documents directory.

I hope this helps.

Integrating non-ARC source into an ARC project

Tuesday, July 2nd, 2013

There is little to no reason to not be using Apple’s Automatic Reference Counting (unless your product is truck in an ancient runtime – pre iOS 4 and OS X 10.6). But, if you have some legacy code that gets compiled into an ARC enabled project, here’s a little trick using C macros (you can name them whatever you want, we use the WB, for “Wooly Beast”, prefix):

#ifndef WBRetain
#if __has_feature(objc_arc)
# define WBRetain(obj) obj
# define WBRetain(obj) [obj retain]

#ifndef WBRelease
#if __has_feature(objc_arc)
# define WBRelease(obj)
# define WBRelease(obj) [obj release], obj = nil

#ifndef WBAutorelease
#if __has_feature(objc_arc)
# define WBAutorelease(obj) obj
# define WBAutorelease(obj) [obj autorelease]

Some examples of usage:

// an autoreleased object
MyObject *obj = WBAutorelease([[MyObject alloc] init]);

// a manually released object
MyObject *obj = [[MyObject alloc] init];
// do stuff...

For easy cut-and-paste, check out the gist.

CoreData + iCloud, Buyer Beware

Monday, February 4th, 2013

Back when iOS 5 was released, it was introduced having support for Apple’s new “cloud service”, iCloud. Dutifully, Apple provided developers with an API to store and access data in iCloud, and their usual Apple way, attempt to implement the “heavy lifting”.

We can now store small bits of key-value data, quickly and easily, to be shared amongst our devices.

Additionally, documents can be “magically” store with minimal additional effort from previous document support.

Finally, the coup-de-gras, is the ability to sync our Core-Data backed data, again, with only the smallest number of changes to current implementation.

To help its developers along, Apple provides sample projects and code snippets to demonstrate the ease by which these magical technologies may be easily incorporated.

Even at the latest local CocoaHeads meeting, the presenter puts together a demo that shows the wonders of using CoreData plus iCloud, and we all applaud in approval.

Others might have disagreed, however.

  • No Identity apps had their tush bitten by a released application.
  • Notable Mac developer, Bare Bones Software (at this time) is still struggling with getting their app, Yojimbo, to play nice with iCloud (although, in all honesty, they might have come from a slightly different direction with converting the now defunct MobileMe support to iCloud)

Not trying to be a nay-sayer, but this is not comprehensive list of complaints we have heard. We haven’t made the transition on Wooly Tasks yet, so we are not speaking from first-hand knowledge, but best to go into the effort with eyes-wide open.

NSDates and Fractional Seconds

Wednesday, July 18th, 2012

A recent overhaul to Wooly Tasks allowed me to manage and query for Task records quicker, more easily, and more reliably. However, I quickly ran into a silly snap when ordering lists of Tasks based on their due dates.

Would you care for another date?…

The recommended method for adding time to a NSDate is by setting up a NSDateComponents object and adding the components to the date object that you want to change. Behind the scenes, the OS will handle the cases of Daylight Savings time changes and Leap Years correctly. Simply adding a NSTimeInterval does not.


NSTimeInterval oneHour = 3600; // magic number! 60 seconds * 60 minutes
NSDate *newDate = [date dateByAddingTimeInterval:oneHour];


NSDateComponents *components = [NSDateComponents new];
[dateComponents setHour:1];
NSDate *newDate = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:date options:0];

The NSDateComponents class interface for setting the hour uses a NSInteger, and not a float or double. This is true of all the other components:

- (void)setDay:(NSInteger)v;
- (void)setHour:(NSInteger)v;
- (void)setMinute:(NSInteger)v;

Dates gone bad…

OK, now we know the correct way to add time to a date, let’s look at something that could bite us in the ass. In the case of Wooly Tasks, we limit due dates to have granularity of every 5 minutes. We also prepopulate a new task with a date that falls on the hour, and is at least 30 minutes from the moment the task was created. So if the current time is 12:34 when we create the task, then we’ll choose 2:00 instead of 1:00 as the due date time. We call this normalizing the due date.

The problem exists, if we create a couple of tasks and normalize the date something like:

NSDate *date = [NSDate date];
NSUInteger unitFlags = NSMinuteCalendarUnit+NSSecondCalenderUnit;
NSDateComponents *components = [[NSCalendar currentCalender] components:unitFlags fromDate:date];
NSInteger hour = ([components minute]<30) ? 1 : 2;
[components setHour:hour];
[components setMinute:-[components minute]];
[components setSecond:-[components second]];
date = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:date options:0];

This will wind the minutes and seconds back to hh:00:00, and the hour ahead by one (two if the date was less than 30 minutes from the next whole hour). Unless you examine the actual NSTimeInterval of these dates, then several created within a short period of time (for our example, within 5.5 seconds of each other) that might appear to be the same time:

Date 1:

July 18, 2012 4:31:39 PM PDT
July 18, 2012 6:00:00 PM PDT

Date 2:

July 18, 2012 4:31:45 PM PDT
July 18, 2012 6:00:00 PM PDT

Each date above is shown with four values: the raw date, the raw date in seconds*, the normalized date, and the normalized date in seconds*. (* number of seconds since January 1st, 2001 GMT). What you notice is that the seconds display have a fractional part that doesn’t get reflected by the user readable display.

This becomes problematic in applications that want to sort records by dates as the primary sort key, and another criteria for a secondary sort key. Particularly so when the coarseness of the dates is less than at the seconds level. For instance, if we sorted the above normalized dates, then record with Date 2 would appear before record with Date 1, even though to the user they would appear to be the same. In cases where the secondary sort criteria would have put a record with Date 1 before Date 2, this sorting would have failed to do so.

A Good Date…

There is no way to remove these fractional seconds by using -dateByAddingComponents:toDate:options: because -setMinute:, as noted above, accepts a NSInteger and not a floating point value type. We can easily modify our code above to handle that using our handy-dandy function, trunc():

NSDate *date = [NSDate date];
NSTimeInterval seconds = trunc([date timeIntervalSinceReferenceDate]);
date = [NSDate dateWithTimeIntervalSinceReferenceDate:seconds];
NSUInteger unitFlags = NSMinuteCalendarUnit+NSSecondCalenderUnit;
NSDateComponents *components = [[NSCalendar currentCalender] components:unitFlags fromDate:date];
NSInteger hour = ([components minute]<30) ? 1 : 2;
[components setHour:hour];
[components setMinute:-[components minute]];
[components setSecond:-[components second]];
date = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:date options:0];

iOS: UIMenuController

Tuesday, June 12th, 2012

File this one under: For my own future reference.

UIMenuController was introduced as public API in iOS 3.0 (along with UIPasteboard and Copy and Paste functionality). This is now a technology we take for granted in the iOS world, but it really wasn’t that long ago that Apple hadn’t provided this seemingly basic service.

Recently I was using this API in DeepDish GigBook to update some fairly crufty workflow. I am not going to explain how to use UIMenuController, as the documentation is fairly straight forward. What I will mention is a few “gotchas”.

1. There is no target for an UIMenuItem.

It is whomever is the First Responder. In other words, your controller class probably (in most cases) is what will handle the actions, so you want to make sure it can become the first responder. Add the following to your controller implementation:

- (BOOL)canBecomeFirstReponder
    return YES;

IF you don’t do this, then passing the message -setMenuVisible:animated: to the UIMenuController will have no effect.

2. Implement - (BOOL)canPerformAction:(SEL) sender:(id) in your controller:

There is little reason not to, and many reason why you should. This will be implemented in the same controller that also implemented -canBecomeFirstResponder. This will allow you to enable or disable (effectively hiding) any menu options you may or may not want at any particular time. It avoids having to recreate the menu items list every time the user invokes your menu through whatever gesture.

- (BOOL)canPerformAction:(SEL)action sender:(id)sender
    if ( action == @selector(myMenuItemMethod:) ) {
        return YES;
    else if (...) {
        return ...;
    else {
        return [super canPerformAction:action sender:sender];

Of course, there might be situations where the same view might support different menu configurations depending on some context, in which case you probably do need to rebuild the menu list each time. But in case where you don’t…

3. Remember that your menu items are persistent:

Whatever menu items you add will remain there until they are set again. If you think about it, this makes sense since UIMenuController is a singleton.

This one bit me due to two reasons. 1) I didn’t have -canPerformAction:sender: implemented, 2) I assumed that menu items list must be rebuilt prior to each invocation of the menu. What happened was a different subview was presented within the main view of the controller, and the subview contained an UITextView. When the user double tapped the text view, and had some text on their pasteboard, the Paste menu option was displayed, along with the other menu options already installed by an earlier menu displayed in the same view. Oops.

The first solution was to nil out the menuItems when the menu was dismissed. This seemed a bit of hack. The better solution was to follow item 2 above since my menu items never changed as long as I was in this particular view. In this case, since a subview only required the basic Copy, Cut, Paste, Select, Select All, etc. the controller would return NO when the controller itself was no longer the first responder. Revisiting our implementation of -canPerformAction:sender: from above:

- (BOOL)canPerformAction:(SEL)action sender:(id)sender
    if ( action == @selector(myMenuItemMethod:) ) {
        return [self isFirstResponder];
    else if (...) {
        return ...;
    else {
        return [super canPerformAction:action sender:sender];


What’s Happening

Wednesday, June 6th, 2012

It’s been quiet on the Wooly Blog front. Too quiet.

To be honest, it is because we spend our days writing code and not writing prose. But, communication is key, and everybody wants to know their favorite Wooly company is still alive and kicking.

We have noticed that Wooly Tasks is a bit long for an update. All I can say is that a pretty nice update is in the works. What to expect:

  • New task management engine to more efficiently and reliably track and manage the tasks.
  • Printing and Twitter support (paid version only)
  • New UI layout to show the most important information quickly, and additional details when you desire them.
  • On iPad, removed hideous paper pad background. It wasn’t our finest moment.
  • iCloud integration and synching between devices (paid version only).
  • Stability enhancements (ok, we fixed some bugs).

On the Wooly Wind Chill side of things, we are looking into being able to integrate your favorite weather source for tapping into current temperatures and wind speeds. The first version will roll out with just a couple, and subsequent versions will add more.

On the contracting front. We are still helping Deep Dish Designs make their wonderful iPad Music application, DeepDish GigBook. While we can’t state specifics, we do know a new version with some very useful enhancements (do we sound a bit biased?) that both companies worked hard on putting together will come out “soon”. Current shipping version in the App Store is 1.6.2, so when you see a version number greater than that, then that “soon” time has arrived.

Speaking of iOS contracting services. If you have a funded product idea that you want Wooly Beast Software to help you bring to market, please feel free to contact us at

Finally, after considerable discussions with management, we have embarked on an exciting new project. In this post, we will not go into a lot of details of what it is, because there are still some things to work out at our end. However, we can say it will involve a bit of this: 

and this:   

and a whole lot of these guys:

That’s about it for now. Next installment we’ll discuss a bit more on what’s going on with our new project, and chronicle the steps up to release.


WWDC 2011 Keynote

Monday, June 6th, 2011

No, I’m not there. :-( As of the time of this writing (9:30am WWDC time), the energy is palatable for this year’s event even 600 miles north of San Francisco (one of my all time favorite places to be) up in Portland.

We already know that Lion (Mac OS X 10.7) will be “announced” (it already really has been, just not the minutia), iOS 5 (same…it exists, no real details), and iCloud (more heavily covered…ie streaming music and a music locker, but free MobileMe services too?). What we don’t yet know is what the “Just one more thing…” is all about.

We know there is something afoot due to this image taken inside Moscone West this morning: (image no longer available)

I originally speculated with @CocoaGeek that this might just be the banners seen already that read “Lion + iOS 5 + iCloud = WWDC11″. However, as @CocoaGeek correctly pointed out to me, this doesn’t make a lot of sense since those have already been announced, even if no details have been given.

So, at 10:00 am (WWDC time) we’ll begin to know that all this is about. All I know is that 2011/2012 is going to be very, very good years to be an Apple developer.

Will update as more information flows in….

10:00 am update…

Mac OS X Lion “announced’ along with 10 new features (out of a claimed 250) being showcased:

  1. Multitouch gestures with trackpads
  2. Full screen apps (meant for smaller screen laptops/devices)
  3. Mission Control (kind of like Exposé + Spaces). A simple gesture gives you a bird’s eye view of everything on your system.
  4. Missed this one…will add it once I can get the skinny on it. Ah, I guess it was the Mac App Store. Nothing terribly new, other than it has become the number one channel for buying PC software.
  5. Launchpad, a new launcher a’la iOS Springboard for the Mac OS. Apparently also employs a sandboxing scheme.
  6. Resume (Nice!) allows you to return to the exact state of the app and its documents
  7. Auto Save (enough said)
  8. Versions… version control for everyone (I wonder if it is based on Git? :-)). Time Machine for all your documents. Who doesn’t want/need that?
  9. AirDrop (Yes!) peer-to-peer WiFi based network (what?! No bluetooth love!?)
  10. with updated UI and other enhancements.

Available only via the Mac App Store, and only $29.99!! Wow!

10:34 am update…

OK, that’s the 10 features they chose to show-case. Looking forward to hearing what is in iOS 5. iCloud being saved for last, so I expect great things. Plus, don’t forget our “One last thing…”

iOS 5 Top 10:

  1. Notifications. Yes! This was a mess and very intrusive. Now can swipe down from top to see current list of notifications.
  2. Newsstand, iBookstore for magazine and newspaper publishers. Nice idea. I wonder how many Indie developers this impacted?
  3. Twitter integration! OK, wow. Explains a few moves made by Twitter over the past few months, particularly with authentication and third-party app support. Again, how does this impact the Indies?
  4. Safari (updated). Reader support (as can be found in Safari 5 for Mac), very nice. Reading List, for saving for later. Tabbed browsing, on the iPad anyhow (Excellent!).
  5. Reminders (Hmmmm… Wooly Tasks killer I think). Lots of interesting features that I had also thought of adding, but Apple has 1000s of more engineering resources than I do, so they beat me to the punch. Ah, the nature of the business. We’ll see.
  6. Camera (updates). Lots of enhancements, mostly in making taking a picture faster and easier. Using the up volume button to take a picture will be really nice. Rule-of-thirds guides. Built-in editing of photos.
  7. Mail (updates). More composing and editing options, in particular, rich-text formatting (YES!). Introducing a new keyboard layout that is thumb-centric and available system-wide.
  8. PC Free…no more tethering!
  9. Game Center
  10. iMessage, new messaging service for all iOS devices. Yay! iChat for iOS

AirPlay mirroring.

iTunes syncing wirelessly.

Available Fall 2011.

11:20 am Update…

iCloud. The Digital Hub that Steve Jobs talked about in 2001 has now moved to “the clouds”. iCloud stores your content “in the cloud” and wirelessly pushes it to all your devices.

MobileMe “wasn’t our finest hour”, but “we learned a lot”. MobileMe is dead. iCloud will subsume all the services of MobileMe, but everything is rewritten from the ground up, and the best news of all…

…it’s FREE.

iCloud is invisibly integrated into apps that need synching of data, such as Mail, Contacts, Calendar, etc. Wireless back-up (a’la “PC Free” feature above). Also backup purchase of iBooks, music, apps, camera roll (on iPhone), etc.

iCloud also has a feature called “Documents in the Cloud” for syncing Pages, Numbers, and Keynote documents. For developers, there will be an iCloud Storage API. And, it will work with PCs as well.

iCloud allows photos taken on your iPhone to automatically be synched onto your iPad. No more needing to tether, sync, sync, sync, … Up to 1000 images stored on your iOS devices, and anything you want to permanently keep, you just need to move into an album. Photos remain for 30 days, so grab them or lose them. There is a Push Photo Stream builtin to camera rolls which is where the syncing takes place.

iCloud is WiFi only due to immense amount of data being pushed. When carriers can reliably offer 4G or greater, then I’m sure it will move to the celluar network.

Finally, there is now iTunes in the Cloud. Buy a song, sync with all devices, automatically.

10:50 am update…

Just in time for “One more thing…”

iTunes Match. For those songs that you ripped from your personal CDs. iTunes will scan your music for non-iTunes purchased music, and voila, your songs are automatically in the cloud. No uploading needed, if they already exist in the iTunes Store. For the rest, they are uploaded. This is the rumored “Music Locker”, and it costs $25 a year (but if you had MobileMe, you still $74 ahead).



Static Libraries woes with categories and iOS

Friday, May 20th, 2011

Like most developers, I assume, I have a lot of utility functions and category methods that I rely on from project to project. Importing all those files into each project, while allows customization, does tend to be tedious, error-prone, and a bit amateurish (IMO). So, I created several stand-alone libraries for Core Foundation, Core Data, and UIKit “extensions”. Simple, no big deal. Just don’t forget to add -ObjC via the Other Linker Flags to your Build Settings of the project that is linking to the static libraries. (See Apple’s Technical Q&A QA1490).

Unfortunately, there exists an issue with the linker where this linker flag doesn’t work as advertised in certain environments (iOS and 64-bit Mac applications) when you have only categories defined, but no classes. When you build your application, you not get any errors about unrecognized categories (assuming you have defined and exposed them via #import header correctly).

When you merrily go about running the application and it tries accessing one of these categories defined in a static library, you get an exception thrown that reads a bit like:

2011-06-04 08:34:50.823 <App Name> [24476:207] +[<Class> <method>:]: unrecognized selector sent to class 0x68e00

In this case, I was calling a class method, but instance methods will be affected as well. Also, if it isn’t obvious, the class address will be different from session to session.

So, the solution for now is to replace -ObjC with either -all_load or -force_load.

Using -force_load requires a path to the archive (static library), whereas -all_load is a shot-gun approach for all archives linked into the project. Each forces the linker to pull in all object files from the archive(s). This is not perfect in that it would be nice to take advantage of the linkers ability to strip out unused symbols, among other potential issues (such as forcing loads of other symbols from other, possibly unknown, archives).

As far as I can tell, there is no harm in defining in Other Linker Flags both -ObjC and either -all_load or -force_load, nor do I see an advantage to it. -all_load or -force_load pretty much override -ObjC entirely.

Xcode 4 and Sharing Archives

Tuesday, April 19th, 2011

Based on discussion in

In Xcode 3, as it turns out there is bug when building projects that have dependencies on external static library projects. When these projects are pulled over into Xcode 4, this issue manifests itself in the inability to share an archive properly as an .ipa file. Instead we get a .xcarchive file. Also, attempting to validate the archive gives us the following error message:

“<AppName>” does not contain a single–bundle application or contains multiple products. Please select another archive, or adjust your scheme to create a single–bundle application.

The solution is modify the “Skip Install” setting of each static library to be set to “Yes” instead of the default “No”.

The bug in Xcode 3 is that even though “Skip Install” is set to “No”, it seems to be ignored, and the output is not placed in the usr/local/lib directory within the archive.

Software Development

Monday, March 28th, 2011

Developing software is a combination of art and science. The science is mostly math, and of that, mostly logic and set theory. Although, recently I was able to brush off my Mathematics degree to apply a bit of linear algebra and trigonometry to develop a pretty cool iPod-like control for use in GigBook (published by Deep Dish Designs LLC) and a future update of Wooly Wind Chill. More about that at a later date, hopefully not too far in the future.

The art aspect is both the visual (graphic) aspect of the product, and having the discipline and understanding that sometimes there is too much of “good thing”, when in reality “less is more” fits the bill better. The art aspect also comes in when finding elegant solutions to tough problems that the user/customer will find pleasing. In a nutshell, there is a real “art” to creating compelling solutions to interesting problems.

On top of that, there are the thousands of details to manage. Literally. In a large(r) iOS project,  there are thousands of lines of code to (mostly) remember, hundreds of logic paths, hundreds of assets in the form of source files, images, sounds, resource files, etc. On top of that, no software is bug free or 100% perfect, so managing the bucket of bugs, as well as identifying and tackling improvement changes (regardless if the user sees them or not), becomes an art unto itself.

Spreadsheets, bug databases, version control, and good old fashion hand written log books become essential tools to tame this tide of data and information. Again, the science aspect, if you will.

So, if things appear to be moving slowly, know it is not just because developing software is (often) hard, it also requires juggling a lot of little things, getting them put in the right place, and keeping them there from day to day without “dropping” any of them.

Like Dr. Hathaway says in Real Genius, “We’re not making cheese sandwiches!”