URL Shortening for Mac OS X and iOS

Today I’m releasing version 1.0.0 of URLKit, a library to find and shorten URLs for Mac OS X and iOS applications.

URLKit was written to order to provide URL shortening services to messaging applications where users may be providing multiple URLs in a single input buffer. I needed the ability to shorten multiple URLs at once and to do so without slowing down the main user interface.

URLKit is implemented using Grand Central Dispatch’s operation queues, so your main UI queue is never blocked by URL shortening operations.

Using URLKit is easy:

@interface MyController : NSObject
@end
 
@implementation MyController
 
- (void)doSomethingAwesome
{
    const URLShortener *shortener = [URLShortener defaultURLShortener];
 
    const NSString *text = @"hello, this is cool: http://newoldage.blogs.nytimes.com/2013/02/01/caregiving-laced-with-humor/?hp but this one isn't that cool http://religion.blogs.cnn.com/2013/01/29/poll-quarter-of-americans-say-god-influences-sporting-events/";
 
    [shortener shortenTextWithURLs:text observer:self];
}
 
- (void)textWithURLsShortened:(NSString *)text
{
    ...
}
 
@end

URLKit can be found at https://github.com/dcgibbons/URLKit and is licensed using the Apache 2.0 license. Comments and patches are welcome!

Project Dependencies and Include Files in Xcode

I have read a lot of how-to guides on blogs over the past few years on how to set it up Xcode sub-projects so you can build your project, a dependent sub-project, and have all the header files and libraries be found. Invariably, this involves changing Xcode project settings both in your main application, and in the sub-project so that everything works out. This is wrong!

The proper way to build sub-projects is that a user of your sub-project does not have to do anything but:

  1. Include the .xcodeproj project file.
  2. Add the project to the top project’s dependencies.
  3. Link against the proper library.

If you are having to do more, then the sub-project was not designed correctly.

As it turns out, Xcode already does this right, but the proliferation of how-to guides usually get it wrong and make developers go through more hoops than they need to. Let’s walk through doing it the right way. Note: this post was written with Xcode 4.4 and 4.5 in mind, so older versions may have had different ways of doing things.

For the purposes of this example we need something simple. Let’s just write a Hello World application that uses an external framework to get the text – it will demonstrate all that we need. Also, we will only cover projects targeted for iOS within this post, but look for a follow-up post that discusses extending these projects to work on Mac OS X as well.
Continue reading Project Dependencies and Include Files in Xcode