views:

41

answers:

1

Given: An application that accesses a directory of files: some plain text, some binary files that adhere to a particular NSCoding implementation, and perhaps other binary files it simply doesn't understand how to process.

I want to: Be able to figure out which of the files in that directory adhere to my NSCoding class, and I'd prefer not to have to fall back on the naïve approach of loading the entirety of each file into memory, attempting to unarchive each.

Anyone have an elegant approach or pattern to this problem?

+1  A: 

The intention of the Universal Type Identifier (UTI) system is to prevent this otherwise impossible-to-solve-elegantly problem. If the three file types don't have distinguishing UTIs (and filename extensions), you're probably out of luck. If this is a problem you see coming and still have control of the files' generation, give them unique UTIs and declare those UTIs in your app's Info.plist.

Barry Wark