Friday, January 29, 2010

iPhone Friday - January 29, 2010

Hello and happy Friday.  Here is a quick iPhone/iPod touch wallpaper for your visual amusement.  Cheers!

Thursday, January 28, 2010

Code Completion in Xcode: How to make your own text macros

[Update] There seems to be an issue with text macros in Xcode 3.2.1 (possibly 3.2) on Snow Leopard that when using the "usual" was (as outlined bellow) code completion for text macros stops working. If you delete the HOME/Library/Application Support/Developer/Shared/Xcode folder and relaunch Xcode, Xcode will add the Shared/Xcode folder back and auto completion and text macros come are enabled in the editor. Editing the xctxtmacro file in the application binary file does not enable the newly created text macro in the Xcode text editor either.

We are looking into a fix and will post it as soon as we know more.

Recently Don showed me a little trick to help me with my debugging skills - as I am not a coder by trade but earnestly try my hand at it. It has to do with "compiler directives" used to log the current method being called (with the log being within the scope of the method). It is as follows:


Don then told me about the "compiler directives and that there were three he thought would be useful for me, __LOCATION__, __FILE__ and __LINE__. Which concatenated in the NSLog statement looks like this:

NSLog(@"FILE, FUNCTION, LINE: %s, %s, %i", __FILE__, __FUNCTION__, __LINE__);

Great! I love this, but now I have to remember it - and it's not really going to change. So I looked into the Xcode documentation and found out about text macros.

There are several that are built-in and that I've been using since day one; such as if, ifelse, init, nsma and others, but my favorite being log.

I'm a fan of templates, snippets, code sensing, auto-completion, text macros or anything reusable to help expedite the build process. I wanted to start utilizing this feature within Xcode and need to learn how.

What I found is that it's quite simple to make your own text macros and that you can use all of the predefined Xcode text macros as an excellent starting point. There are a few things to do before we can begin creating our text macro and that is to create the files necessary for Xcode to load them up at launch time.

Creating Xcode user-defined text macro folder and files.
Go to your Xcode application file (root/Developer/Applications/).
Right-click (control-click) and Show Package Contents...
Navigate to (Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/).
Select the Objective-C.xctxtmarco file and Copy it (command-c).
Open a new Finder window and select your Home folder.
Navigate to (Library/Application Support/Developer/Shared/Xcode/).
In the Xcode folder Paste (command-v) the Objective-C.xctxtmacro file.

As you can see we have created our working copy of the text macros description file and moved it to it's new home (being sure not to overwrite the original). Now we can dive into our editing and creation of our new text macro.

Creating your Xcode text macro.
The Objective-C.cxtxtmacro is basically a ascii plist so open it with your favorite plist editor. In this case I'm going to use Xcode by dragging the file onto the Xcode icon in my Dock.

As you can see it's an Array with around 26 items, each of which is a Dictionary. Take a look at a few if you'd like as they are a wonderful reference. Also, if you'd like go back to the Xcode package, copy those other text code files elsewhere and look at them. It's always good to have reference/source materials.

We're going to go down to the last one, select it and then click on the "+" symbol/tab to the right of the selected cell. This will add a new Item to the plist root Array which will be our new entry (text macro definition).

Select the new Item and change the Type from String to Dictionary. Now tap on the disclosure triangle (the left side of the selected cell), this will rotate the triangle from pointing right (collapsed) to pointing down (expanded). You may also notice that the "+" symbol to the right changes into a set of lines when the Item is expanded. This let's us add "children" name/value pairs to our new Item.

There are a few "children" name/value pairs we need to add to our new Item to make it function and they are as follows (to the best of my knowledge):
  • Identifier - This describes the macro's language (parent).identifier.
  • BasedOn - This is the (parent) language (objc).
  • IsMenuItem - Boolean value. This creates a menu item in Edit menu.
  • Name - The name listen in the (above) menu item.
  • TextString - The actual string that will be inserted via the text macro.
  • CompletionPrefix - This what you type in as the key for the text macro.
NOTE: These are the 6 that are necessary in Xcode 3.2 and later. I believe in Xcode 3.0.x - 3.1.x you also needed IncludeContexts, which in Xcode 3.2 you can use IncludeContexts (array) and ExcludeContexts (array) to control in which blocks the text macro will show up in the auto-complete list.

Adding the "Names".
In our new Item we're going to add the six new children name/value pairs - all of which are going to be of Type strings. Just click on the tab to the right six times.

Go ahead and name the new children's names as outlined above. You can click on the first one and name it then tap Tab twice to quickly move to the next one (name) beneath it. It should look like this:

Filling in the "Values".
Now comes the fun part - filling in the values. For us, for this example we're focusing on a NSLog text macro, so go ahead and fill in the values with the following:

  • Identifier - objc.flog
  • BasedOn - objc
  • IsMenuItem -YES
  • Name - Function (NSLog)
  • TextString - NSLog(@"FUNCTION: %s", __FUNCTION__);
  • CompletionPrefix - flog
This is to say that when we type "flog" and then press the Escape key (esc) the drop down will present us without function and we can press Tab or Enter to finish the code completion. Your Item should look like this:

Let's enter another one. It is almost the same but contains the File and Line number as well (as mentioned at the start of this article).

NOTE: You can collapse the flog Item we just made, select it, right-click (control-click) and Copy then Paste and it will append a copy flog Item beneath the original flog Item - then it's just a couple of text edits and we're done (in bold).

The values are as follows:
  • Identifier - objc.fflog
  • BasedOn - objc
  • IsMenuItem -YES
  • Name - File, Function, Line (NSLog)
  • TextString - NSLog(@"FILE, FUNCTION, LINE: %s, %s, %i", __FILE__, __FUNCTION__, __LINE__);
  • CompletionPrefix - fflog
You can name your Identifier and CompletionPrefix whatever you'd like, as long as it does not conflict with any existing completion identifier. I use flog for Function Log and fflog for File Function Line Log. Here is what the new fflog Item looks like (under the first flog Item):

Now simply restart Xcode for your new text macros to take affect. All you need to do is open one of your (Objective-C) projects type in flog and press esc then tab or enter/return - and POW - the entire function is inserted for you with just a couple of keystrokes. Nice, simple and elegant. Thank you Apple for making my coding experience a little less... cumbersome.

This is only the beginning of what you can do with text macros. But as I mentioned in the beginning of the article, I'm not the very best coder. As I learn more tricks or reasons for more complicated macros I will go ahead and blog about them here for you. I hope this helps you as much as it helps me.

Will you set up text macros in your own Xcode development environment? Do you like text macros? Would you like to know more about them and possibly have us do a follow up blog posting on them? Comment below. Don't be shy. We'd like to hear from you. You can also follow us on Twitter. Cheers!

Wednesday, January 27, 2010

iPhone SDK supports iPad development

"We rewrote all of our apps for this display. the iPhone SDK supports development for this now... and we're releasing it today." - Scott Forstall, Apple's SVP of iPhone Software.

More at Engadget.

[Update] Get the iPad SDK at

Apple announces the Apple iPad - the wait is over. Now for the wait. [Update 1,2]

Today Steve Jobs of Apple announced the new Apple iPad. Now that the wait is over.... we wait. We wait for the announcement date. We'll wait in line outside the Apple Store when that day comes. And we'll wait all the way home until we open the box and start it up. I can hardly stand the waiting already.

Thank you to Engadget for the live blog feed and pictures. We'll update accordingly. Cheers!

[Update 1]: After Steve introduces the iPad and does his usual demo he starts to talk specs:
  • .5 inches thin
  • 1.5 pounds
  • 9.7" IPS display
  • 1024-by-768 (132 ppi)
  • Full capacitive multi-touch
  • 1GHz Apple A4 chip (thank you PA Semi)
  • 16, 32, 64 GB Flash storage
  • Bluetooth 2.1 + EDR
  • WiFi 802.11a/b/g/n
  • Accelerometer & Compass
  • Speaker, Microphone, 30-pin connector, SIM card tray
  • 10 hour battery life
  • -with over a month of standby
  • Multiple languages and characters simultaneously
  • ...and I'm sure there's more
[Update 2]: The price...
  • 16 GB - $499
  • 32 GB - $599
  • 64 GB - $699

3G models cost an extra $130.00 so that's $629, $723 and $829.

The iPad will be available in 60 days (90 days for 3G models).  So that's what, March and June.  Ah, let the anticipation of the release day begin!

How do you feel about the iPad?  Will you be in line for it?  Will you get the standard version, or wait the extra 30 days for the 3G enabled version?  Lets us know, comment bellow.

The Apple Tablet: Secret snapshots and product history

In the wee hours of this morning the interwebs are all a chatter about the Apple Press Conference that is going to start in a matter of hours and the (hopefully) debut of the Apple Tablet (name TBA).  The people over at have a post of what they believe may be the ├╝ber-device, packed in what appears to be a display case (for after the announcement, for the press and general public to oooh and ahhhh over).

Along with the non-confirmed product image blog post, Laura June has a blog entry with the (almost) complete history of the products conception and purposed debut.  It is a interesting read full of images of patents as well as artist renderings.

The anticipation is palpable and Apple has a recent track record of delivering quality products for the general consumer that are be-seen-with devices (iPod) as well as intuitively accessible iconic status symbols (iPhone).

Will Apple get it right with the new device?  Will the device be all that we hope it to be?  Will it sell between one and five million in the first year?  I don't know the answers to these questions, but I do know that whatever it is we will be in line when it comes out so that we can purchase another piece of Apples computing history.

What do you think?  Will you be in line with the rest of us, or will you be on the sidelines, waiting for a personal review?  Let us know and comment bellow.

Tuesday, January 26, 2010

iTunes "deep links" demystified: How to link to iTunes/App Store content

Last week Don posted an entry on Creating easy-to-read links to the App Store for your applications and company, to which I would like to add a few little gems of knowledge that we have learned while dealing with linking to iTunes and its content.

Apple recently create a few different way to create/generate links to the iTunes and App Store - making it easier for developer and average people alike to link to content.  First a quick overview of the ways to link to content in iTunes.

Creating links from within iTunes
Apple has made it easy for people to share links to music, movies, television shows and apps within iTunes.  All you need to do is open iTunes, navigate to your desired content and then either right-click (control-click) on the album image or the disclosure triangle next to the BUY button and you are presented with a menu - pick Copy Link.


These are just a couple of ways to pull the information.  Apple has also added ways to share links via Facebook, Twitter and via email.

So what does this give you?  Well in the case of Mr. Bowie's latest live concert album, it gives you the following link:

And what's new about this link is not that it has the standard web redirect, but Apple now has an "iTunes Preview" web page that is much like the iTunes view:

iTunes (above)

web page (above)

Now how does this translate for movies and television shows?  Lets look at Whip It (movie) directed by Drew Barrymore:

Clicking on the disclosure triangle and selecting Copy Link gives us the following:

When clicking on the link we are presented with the earlier behavior of the iTunes links.  That is to say a we are presented with a web page that gives us a redirection and then launches iTunes.

So what do we see that is different between the first link and the second link?  They both start with, but that is where the simularity ends.  What happens with the first link (Music) is it is sent to a web page with the content inline, as the second link (with the WebObjects path), actually generates a page and then redirects internally to the following link (which launches iTunes):

Notice that the prootcal is not "http" but rather "itms" for iTunes Music Store.  This tells your computer to launch iTunes and then direct itself to the ID (333687225).

Great, so we have two different behaviors from the iTunes linking mechanism.  But wait, there's more!

Linking to apps in the App Store (within iTunes) works much the same way as movies and television shows.  A Copy Link process gives you a link to the app much like the music link (for instance, The White House app):

It looks the same as the music link with the iTunes Preview, but it functions like the movie link with a generated redirection page and then launches iTunes and loads the apps landing page.

iTunes Link Maker (iTMS Link Maker)
The other way to make links is to use the iTunes Link Maker.  We've all seen the following image that links to iTunes:

This image and it's associated link are generated by iTunes Link Maker by going to the site and searching for the content in iTunes that you want to link to.  The process is simple.

1.) Go to the iTunes Link Maker web page (link).

2.) Enter the item or artist you wish to link to then click Search.

3.) Click on the "arrow" button for the specific item you wish to link to (Orchard's Craps APP).

4.) Copy and paste the generated HTML link into your web page and presto, you have your own iTunes link.

The final link looks like this:
Orchard's Craps
It looks just like the first iTunes button above, but this one opens a web page, then launches iTunes and then redirects to the Orchard's Craps landing page.

Deep Links (for Apps)
Deep Links are new and is what the gist of Don's blog entry is about.  Apple has made it easier for use to link to content in iTunes and the App Store.  Deep Links are simple and straight forward.  A link is created using the prefix and come in three flavors, links to apps, links to your company's apps or a hybrid link to your company's app.

For app developers the problem with deep links is symbols or punctuation in an app.  We need to remove the symbols for the app name to create the deep link.  Remove the following characters:
But what happens if we have an app with a character and there is another application without the character?

As an example we have a series of apps that have a "?" (question mark) at the end of their names; such as Animals?, People? and Places? and if I try to use the simple (application) Deep Link with the following link: it takes you to iTunes but not to the app bur rather to a iTunes search result page with "Animals" as the search search term.

To counter this we use the company/app link: and this will point directly to our application.  Nice.

So now we have a simple way to generate links for our products.  Simple and concise.  But will this work with making links that work within our apps?  The short answer is yes, it will, but the longer answer is, no, not the way you'd want it to work.

Launch the App Store within iPhone/iPod touch apps.
Recently we've been designing our App Catalogue, which we will be pushing out to all of our applications.  It is a directory of all of our apps (sans the current app you are using to review the app catalogue) and has a description of the app as well as a link to the App Store.

The problem with the linking system above is that if we were to use the links in our apps to link to the App Store a series of redirect happen.  You touch the link and then Safari launches, it generates its redirect page and then starts the redirect, then App Store launches and then the app is presented - but that is not the desired effect.

We want our App Catalogue to launch App Store when the link is tapped, not the long way around via Safari.  So how do we combat this?  Well Apple has a reference to an article on Launching the App Store from within an Application (QA1629) which since is missing... so I'll explain what we do.

On our blog, website, and other web links we use the company/app deep link, but for our internal iPhone /iPod touch apps, we use the old phobos link with the application ID.  You can find your application ID by logging into iTunes Connect and managing your applications, list them all, or get details of a particular application.

The linking mechanism on the iPhone/iPod touch is as follows:

Where the ID (bold) is the application ID.  So now that we have an absolute URL that will launch App Store from within our app, all we need to do is the openURL part of it.  As we have our App Catalogue both hardcoded and served up via JSON, we include the URL in the feed (just in case we need to change it).  Our call is simple:

- (IBAction)openAppStoreUrl {
  NSURL *appStoreUrl = [NSURL URLWithString:[application objectForKey:@"appStoreUrl"]];
  [[UIApplication sharedApplication] openURL:appStoreUrl];

and the appStoreURL is (a clip from our JSON respons):

"appStoreUrl": ""

So when we attach the IBAction to the button to make the call, the URL is opened, in effect our app is closed and the App Store opens and takes the user to the application.  Nice.  Now we have a direct way to market our other apps.

So there you have it.  Linking to music, movies, T.V., shows and applications as either a link in web pages, or in use in an iPhone/iPod touch application.

How do you use Deep Links?  Do you use Deep Links?  How do you create your links to iTunes or to the App Store?  Was this article helpful?  Let us know by commenting bellow.  Also, take a moment to follow us on Twitter or join our mailing list.  Cheers!

Friday, January 22, 2010

iPhone Friday - January 22, 2010

Happy Friday.  Today we only have one iPhone/iPod touch wallpaper for you (there may be more later).  Cheers!

Tuesday, January 19, 2010

Objective-C Tuesdays: static variables

In our last episode we looked at the extern keyword and how it's used with global variables. Today we'll look at using the static keyword to make global variables "private" to one .m or .c file.

By default, every global variable in a .m or .c file is external or "public". After each .m or .c file is compiled, the linker combines them together and matches up every global variable declaration with its corresponding definition. If a definition is missing, or a global variable is defined more than once, the linker generates an error.

But sometimes you want a global variable that's only "global" to one .m or .c file. For example, you might have two similar UIView subclasses that each use a global variable named defaultHeight:
// ERROR: won't link

// CoolView.m
// ...
CGFloat defaultHeight = 400.0f;
// ...

// HotView.m
// ...
CGFloat defaultHeight = 300.0f; // ERROR: duplicate global variable definition
// ...
The linker sees the same global variable name defined in two different .m files and fails with an error. One solution is to give the variables unique names, like coolViewDefaultHeight and hotViewDefaultHeight. But if you don't need to use those global variables outside the .m file, you can make them static instead.

When used with a global variable, the static keyword makes the global variable "private" to the .m or .c file where it's defined. So our example would look like:
// CoolView.m
// ...
static CGFloat defaultHeight = 400.0f; // only visible in CoolView.m
// ...

// HotView.m
// ...
static CGFloat defaultHeight = 300.0f; // only visible in HotView.m
// ...
Using static where possible helps you avoid name collisions in larger programs. Next time, we'll look at using static to make a global variable visible only within a single function or method.

Monday, January 18, 2010

Making A Living On The iPhone App Store

Noel Llopis of Snappy Touch, the author of the Flower Garden iPhone app, wrote a very revealing blog post recently where he examined the sales of Flower Garden in depth.

Noel details sales his sales and profits from the app, and talks in detail about different strategies he tried, including creating a free version of the app, a Mother's Day give away contest, creating the App Treasures affiliate group, adding Facebook integration, and adding In App Purchase to Flower Garder.

Friday, January 15, 2010

iPhone Friday - January 15, 2010

Hello and happy Friday!  It's been a busy week here for use at Able Pear and we will have some more exciting news in the next week or so to share with you.  But in the mean time...

It's been rather wet here in the Bay Area (of California), but not as bad as other places.  To which I am offering this set of iPhone and iPod touch wallpapers based on the theme Singing In The Rain.  Enjoy.

And here is a special bonus set:

Thursday, January 14, 2010

Creating easy-to-read links to the App Store for your applications and company

Apple has published a Technical Q&A detailing how to form human friendly iTunes links for iPhone apps. By default, if you use the "Copy Link" menu option in the App Store, you'll find a URL like on your clipboard. It's not too bad, but Apple also allows some friendlier URL formats.

You links to your app using your company name and app name, such as, as well as direct app links like Links to the "artist" page for your company are similar:

The Q&A has more info on allowed characters and what happens when apps share similar names (like

Monday, January 11, 2010

Getting excited about the Apple tablet

The buzz over the forthcoming Apple tablet has been steadily building in recent weeks. Apple is definitely going to announce something new.

John Paczkowski of AllThingsD writes about Apple's upcoming media event in San Francisco on Wednesday 27 January. At this point, pretty much everyone in the tech press and blog world is certain that the announcement will be a tablet device. TUAW sums up the latest rumors and even has some in-depth speculation about issues facing developers as they migrate iPhone apps to the new tablet.

John Gruber of Daring Fireball has chimed in with his well developed thoughts as well (including a follow-up).

As an interesting aside, take a look at the leaked concept video for the Microsoft tablet device code-named Courier.  While the concept interaction that's presented obviously draws heavily on the iPhone, it's still interesting and makes me hopeful that Apple's considerable design talents might produce a really compelling new machine.

Friday, January 8, 2010

iPhone Friday - January 8, 2010

Hey there, happy Friday and a Happy New Year's wishes to you all!

It's been a very exciting past couple of weeks for us here and not just because of the holidays. We announced two new iPhone/iPod touch apps; People? and Places? now available on the App Store. As it was a busy few weeks I did not get a chance to post the iPhone Friday and apologize. Here is one of the Holiday Series that did not get posted.

Also, there's more news! But, I can't tell you yet. Sorry. I can however share with you some of the artwork we're developing for the game - as wallpapers. Enjoy!

Thursday, January 7, 2010

Announcing Places?

Able Pear is happy to announce that our latest application, Places?, is now available in the iTunes App Store.

Places? is a game of questions and answers. Think of a place and Places? tries to guess it.

Answer simple yes/no questions like "Is it a country?" or "Is it in Europe?" When Places? thinks it knows the answer it will guess the place: "Is it France?"

When Places? makes a wrong guess you can teach it the new place and add a new question to ask.

Places? is great game for anyone age 8 and up who loves geography.

Learn more about Places?...

Click here to see our complete list of apps.

Tuesday, January 5, 2010

Objective-C Tuesdays: extern and global variables

Welcome back and happy new year! Last time we looked at global variables and their initialization. Today we'll look at how to share global variables between .c and .m code files.

Frequently, you define a global variable in one code file and use it in another. For instance, the file MyView.m might contain the global variable doubleTapEnabled:
// MyView.m
#include <Foundation/Foundation.h>
// ...
BOOL doubleTapEnabled = YES;
// ...
To use this variable in main.m you might do this:
// main.m
#include <Foundation/Foundation.h>

BOOL doubleTapEnabled;

int main(void) {
  // ...
  NSLog(@"doubleTapEnabled = %i", doubleTapEnabled);
  // ...
This will work the way you expect, but there's a subtle potential gotcha here. Notice that in MyView.m we initialize doubleTapEnabled to YES. When the compiler sees that, it interprets that statement as a global variable definition and allocates space for the doubleTapEnabled variable and sets its initial value.

However, in main.m we don't give doubleTapEnabled an initial value, which makes that statement ambiguous: it could be a global variable declaration for doubleTapEnabled or a definition, with doubleTapEnabled initialized to zero (NO).

The difference between a declaration and a definition can be confusing since they're closely related (and the two words are unfortunately very similar). A declaration tells the compiler that a global variable, struct, class or function exists somewhere. A definition gives the compiler all the information it needs to generate the code for a global variable, struct, class or function.

A statement like
BOOL doubleTapEnabled;
can be either a declaration or a definition. At link time, if an unambiguous definition isn't found, the global variable will be created and initialized to zero; if an unambiguous definition is found, that definition will be used to create the global variable.

So if you do something like this:
// ERROR: won't link

// MyView.m
// ...
BOOL doubleTapEnabled = YES; // unambiguous definition
// ...

// main.m
// ...
BOOL doubleTapEnabled = YES; // unambiguous definition
// ...
You will get a linker error like "duplicate symbol _doubleTapEnabled" because you told the compiler to create the same global variable in two different places.

This is where the extern keyword comes in. You use extern with global variables to create unambiguous declarations. In addition to helping the compiler, it also clues in anyone reading the code that the global variable is defined (and possibly initialized) elsewhere, but you're simply using it here. So we can rewrite our example like this:
// MyView.m
// ...
BOOL doubleTapEnabled = YES; // unambiguous definition
// ...

// main.m
// ...
extern BOOL doubleTapEnabled; // defined in MyView.m
// ...
And now doubleTapEnabled is happily unambiguous everywhere.

It's common style to add extern to all global variable declarations in your header (.h) files and provide a corresponding definition in a source (.m or .c) file. So the header file MyView.h would look like:
// MyView.h
// ...
extern BOOL doubleTapEnabled;
// ...
The source file MyView.m is the same:
// MyView.m
// ...
BOOL doubleTapEnabled = YES; // unambiguous definition
// ...
And main.m now looks like:
// main.m
// ...
#include "MyView.h"
// ...
Next time, we'll look at using the static keyword to make to make a global variable "private" to a source file.