Archive for 'Programming'

Document Management

Here’s an excellent tutorial for you to read all about, as the title straightforwardly describes,

Importing & Exporting Documents in iOS

One of the common tasks that an iOS developer has to do is to import or export documents from his iOS application. For example, suppose you are developing a document reader and you want to allow the user to import documents into your application so that it can be read offline. Also, your reader might also support the exporting of documents so that other applications can make use of the document.

In this article, I will walk you through the different techniques you can employ to allow documents to be imported or exported from your iOS application…

Covers use of UIDocumentInteractionController to export documents, like having a PDF you write show up in iBooks; how to use File Sharing to have iTunes transfer files into your /Documents; and how to set things up to import documents from other applications, mail attachments, and so forth. Nice piece; haven’t seen all this related stuff grouped together so handily anywhere else!

h/t: maniacdev!

Continue Reading →

AFNetworking + FormatterKit

So as has been generally conventional among the plugged in set we’ve been using ASIHTTPRequest for our heavy lifting network needs the last while, but it seems that teh tweeties are all abuzz lately with a new contender for that job:

Screen shot 2011-08-15 at 11.40.32 PM.png
Screen shot 2011-08-15 at 11.40.50 PM.png

Well, those are rather enthusiastic sounding, aren’t they? So what is this AFNetworking thingy then?

A delightful iOS networking library with NSOperations and block-based callbacks

There’s a lot to be said for a networking library that you can wrap your head around. API design matters, too. Code at its best is poetry, and should be designed to delight (but never surprise).

AFNetworking was lovingly crafted to make best use of our favorite parts of Apple’s Foundation framework: NSOperation for managing multiple concurrent requests, NSURLRequest & NSHTTPURLResponse to encapsulate state, NSCache & NSURLCache for performant and compliant cacheing behavior, and blocks to keep request / response handling code in a single logical unit in code.

If you’re tired of massive libraries that try to do too much…

If you’ve taken it upon yourself to roll your own hacky solution…

If you want a library that actually makes iOS networking code kinda fun…

…try out AFNetworking.

Never thought we’d see “networking code” and “kinda fun” in a concatenation. And we have spent waaaaaaay too much of our lives in writing it, that being pretty much the first task everyone finds obvious to delegate to THE MAC GUY on a cross-platform team, we have found. But why yes, the samples do look like pretty nice simple code, and integrated nicely with JSONKit too. So as long as you can require a minimum of iOS 4 for the blocks, which is rapidly approaching “not a problem” status for new projects, that does indeed look worth a look.

Bonus: The acknowledgements led us to FormatterKit, which looks like quite the handy addition to your bag of tricks as well:

FormatterKit is a collection of well-crafted NSFormatter subclasses for things like hours of operation, distance, and relative time intervals. Each formatter abstracts away the complex business logic of their respective domain, so that you can focus on the more important aspects of your application.

In short, use this library if you’re manually formatting any of the following (with string interpolation or the like):

Arrays: Display NSArray elements in a comma-delimited list (eg. “Russell, Spinoza & Rawls”)

Hours of Operation: Format and collapse recurring weekly business hours (eg. “Mon-Wed: 8:00AM – 7:00PM”)

Location, Distance & Direction: Show CLLocationDistance, CLLocationDirection, and CLLocationSpeed in metric or imperial units (eg. “240ft Northwest” / “45 km/h SE”)

Ordinal Numbers: Convert cardinal NSNumber objects to their ordinal in most major languages (eg. “1st, 2nd, 3rd” / “1ère, 2ème, 3ème”)

Time Intervals: Show relative time distance between any two NSDate objects (eg. “3 minutes ago” / “yesterday”)

URL Requests: Print out cURL or Wget command equivalents for any NSURLRequest (eg. curl “” -H “Accept: application/json”

Code you don’t have to write is always the best kind!


Woah! Yep, it is officially, from the author, time to stop using ASIHTTPRequest as active development has ended. His suggestions for where to look forward:


From the people who make Gowalla. A general purpose HTTP lib, built on modern patterns, actively developed. AFNetworking has been gaining a lot of traction over the last few months, so it’s a good bet that it’s going to be around for a while.


A lightweight HTTP lib, actively developed. Also comes in an ARC-flavoured variety.


For applications that talk to REST-based services, lets you map remote objects and store them in CoreData. It sounds like this could replace a lot of code in the right circumstances.


Amazon S3 support has been one of the most popular ASIHTTPRequest features. These days Amazon offers their own SDK for iOS, providing access to S3, CloudFront, SimpleDB and other Amazon cloud services.


The highest-level API listed here. Provides a simple way to upload content to a variety of services, and a UI to make it super easy to drop into your projects.


From the people who make your cellphone. Built by smart people, lightweight, actively developed. :)


SVHTTPRequest is another simple, fast, blocks, etc. option stressing straightforwardness.

Or try Introducing MKNetworkKit + Advanced Networking with MKNetworkKit.

Another MKNetworkKit vote: ASIHTTPRequest is dead, now what?

And RSOAuthEngine is a lean Twitter implementation for MKNetworkKit.

Say hello to FSNetworking: A Small Networking Library for iOS and Mac

AFNetworking / AFNetworking-ASIHTTPRequest eases the transition.

iOS AFNetworking Add-On Library That Provides Accelerated Downloading

OliverLetterer / AFURLConnectionByteSpeedMeasure “is a drop in extension for AFNetworking to measure download and upload speed of an AFURLConnectionOperation and estimate completion times.”

jboehler / AYNetworking “is a set of category with API methods to make it easier to handle requests and response with AFNetworking Framework.”

AFNetworking Crash Course

jaminguy / JGAFImageCache “A fast reliable image cache for iOS built with AFNetworking.”

NSHipster’s NSFormatter

The Minus Sign: “The default behavior of NSNumberFormatter is to use the hyphen-minus to format negative numbers … your text will look much more professional if you use the real minus sign.”


Alamofire / Alamofire : Elegant Networking in Swift

Alamofire Tutorial Part 1: Getting Started and Part 2: Progress and Caching

SwiftyJSON; Nice Web Services, Swift Edition; Working with JSON in Swift Tutorial; Parsing JSON APIs with SwiftyJSON tutorial series:

UITableView Tutorial in Swift using Alamofire, Haneke and SwiftyJSON and UICollectionView version

Continue Reading →

Complex Gesture Recognition

Have in mind doing something that requires gesture recognition, and found out in short order that’s a pretty tricky thing to do? Here’s an excellent article set for you:

Complex Gesture Recognition in iOS – Part 1: The Research

Complex Gesture Recognition in iOS – Part 2: The Implementation

Or for the ADD-inflicted, source is on github for an iOS $N Multistroke Recognizer implementation!

h/t: ManiacDev — check their post for links to $1 gesture recognizer stuff as well if that’s enough to suit your needs.

Continue Reading →


Here’s a possibly interesting collaboration tool: These people who apparently are Yet Another IM Network, because we certainly don’t have enough of those or anything, are doing their bit to stand out from the crowd by providing an SDK that lets you use their platform to share content from your app:

… By giving your users the ability to share with each other in real time, your app will be that much more fun and compelling (see the Sketchee story below). Sharing can also give a big boost in adoption – when a user who doesn’t have your app receives a Kik content message from it, Kik offers to take them directly to your download page where they can install it. All of a sudden you aren’t asking your users to share your app with their friends, but to share content from your app with their friends – content that requires them to get your app to view and interact with it. It’s the difference between inviting someone to join a social network vs. tagging a photo of them that requires them to join the social network to view it.

And best of all, it will only take you 10 minutes to add this kind of functionality to your app…

That does actually sound like a pretty solid reason to adopt this, if your app has content amenable to being shared, yes. And hey, if that brings some bright spark to mind, and you’ve got a couple weeks at loose ends right now, here’s some decent motivation to check it out:

$5,000 awards for the pioneers

To celebrate our beta SDK release, we want to offer some awards to our early adopter developers. We will be awarding $5,000 to the 3 developers who write and launch the best apps using our SDK before August 8th. Learn more about the awards here

h/t: readwriteweb!


Check out the video in ManiacDev’s post on the subject too.

Continue Reading →

Supporting iCade

So you heard about that iCade thing for the seriously retro iPad vibe?


If you’d like a full review, check out

Thoughts on the iCade (and on using it with Flash games)

but we’d just like to note for your development pleasure this bit, if you’ve already decided that would be a neat thing to support in your games:

So how do you add iCade support on iOS? Luckily someone made a library that makes it super easy: – basically you just add a special view to your main view controller which listens to keyboard events, and that view then sends messages to a delegate when buttons are pushed. There’s really not much more to it…

“Super easy” is a good level of integration complexity, yep.


Adding iCade Support to Your Game

Continue Reading →

Tip: Keyboard Area

As you know if you’ve ever tried it, it’s harder than you’d think it ought to be to figure out just where the keyboard is coming up on the screen. Here’s a tip which looks like a good approach:

Calculating Area Covered by Keyboard

I’ve seen several approaches to this so far, but they often hard code a certain position of the view or sizes. Like assuming that the covered view always reaches towards the bottom of the screen or always has a certain amount of space taken away from it by the status bar, navigation bar and possibly toolbar.

The whole thing gets even more complicated by the fact the the coordinate system of the app’s window is always in portrait even though your app rotates. So is the frame of the keyboard which you can get from an info dictionary in several notifications. I’ll show you the most universally working method I was able to come up with…

Those bars at the bottom are usually the tricky bit, we find. If this actually does handle them properly in just that little bit of code, we’ll be pretty impressed!

Continue Reading →

Bezier Path Boolean Ops

This is a solid series on manipulating NSBezierPaths:

How to implement boolean operations on bezier paths, Part 1

This post will focus on finding intersections between individual bezier curves, and the next will show how to implement the boolean operations based on that. The algorithm presented will be able to handle arbitrary closed bezier paths, including those with holes and self intersections.

If you’re impatient, you can skip straight to the commented source code

How to implement boolean operations on bezier paths, Part 2

This time I’ll show how to conceptually perform the four common boolean operations: union, intersect, difference, and exclusive or…

How to implement boolean operations on bezier paths, Part 3

In this final installment I’ll present the algorithm used to implement the boolean operations…

Beats figuring it all out yourself!

Continue Reading →

Core Text Tutorial

This is a rather nice introductory piece to the somewhat underdocumented Core Text framework to go along with the various bits and pieces we’ve noted before:

How To Create a Simple Magazine App with Core Text

This tutorial will get you started with Core Text by taking you through the process of creating a very simple Magazine application using Core Text – for Zombies!

You’ll learn how to:

  • lay formatted text down on the screen;
  • fine tune the text’s appearance;
  • add images inside the text content;
  • and finally create a magazine app, which loads text markup to easily control the formatting of the rendered text.
  • eat brains! Ok just kidding, that’s only for the readers of this magazine.

Good stuff, good stuff.

Continue Reading →

Tip: CoreGraphics Patterns

Here’s a snippet demonstrating, as the title says,

Using Patterns in Quartz2D

There’s not a ton of information out there about how to use patterns with the Quartz framework and drawing patterns, especially about combining it with UIColors ability to create colors with patterns…

Also sample project on github. And what actually got our attention enough to merit a blog note, check out

Stripe Generator 2.0 — “The Ultimate Tool For Web 2.0 Designers”

which looks like a rather nice site indeed for generating stripey background patterns.

Also might want to check out the latest from the ever expanding Wenderlich tutorial empire,

Photoshop Tutorial: How To Get The Repeating Image From A Pre-Made Pattern

h/t: @pzearfoss!

Continue Reading →

Threadsafe Date Formatting


So let’s say you’ve got a project that involves a bunch of repetitive date manipulations, like merging multiple RSS feeds into a single timeline. And having done some timing, and read QA1480, you’re quite aware that

[NSDateFormatter alloc] is insanely expensive. If you’re doing it more than once, YOU’RE DOING IT WRONG.

So you’re doing it only once. And then you find that you start getting a disturbing number of crash reports with terminal lines like

Thread 9 Crashed:
3 libicucore.A.dylib 0x300cafa4 icu::DateFormat::parse(icu::UnicodeString const&, icu::ParsePosition&) const + 120

And that makes you remember, uh-oh … NSDateFormatter is thread-unsafe. Whoops. Well, that throws the above statement for a loop.

However, we can edit that to the actually correct

If you’re doing it more than once per thread, YOU’RE DOING IT WRONG.

by using thread local storage as suggested in this Dropbox forum posting, for something like

That should work out nicely for you.


Note our earlier DateCalculations, Tip: NSDateFormatter Localization, Snippet: Ordinal Days, Snippet: NaturalDates, Code: NSDate (Helper), NSDateFormatter formatting

DateFormatter Reference:

On iOS 7 and later NSDateFormatter is thread safe.

On OS X v10.9 and later NSDateFormatter is thread safe so long as you are using the modern behavior in a 64-bit app.

On earlier versions of the operating system, or when using the legacy formatter behavior or running in 32-bit on OS X, NSDateFormatter is not thread safe and you therefore must not mutate a date formatter simultaneously from multiple threads.

If you’re parsing ISO-8601(JSON) dates, try Date Parsing Performance: NSDateFormatter vs. SQLite instead.

The Hit List Diary #21 – Lenient Date Parsing

FormatterKit has time intervals, and oodles of other goodies.

SwiftMoment: Open Source Swift Library For Working With Dates Inspired By Moment.js

Global Nerdy’s “How to work with dates and times in Swift” articles (so far):

Tempo: “Date and time manager for iOS/OSX written in Swift.”

if you are using NSDateFormatter -setDateFormat: without NSDateFormatter +dateFormatFromTemplate:options:locale:, you’re probably doing it wrong.

CVCalendarKit: “A wrapper around NSDate which provides a convenience way for dealing with dates.”

SwiftDate: “Easy NSDate Management in Swift.”

Timepiece: Open Source Swift Library Providing A Great Syntax For Working With Dates

Predictable Date Formatting “Apple specifically recommends using the “en_US_POSIX” locale [to parse an Internet-style date]”

Continue Reading →
Page 30 of 99 «...10202829303132...»