开发者

What's the fastest way to determine if a file adheres to a particular class's NSCoding implementation?

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 appro开发者_Python百科ach of loading the entirety of each file into memory, attempting to unarchive each.

Anyone have an elegant approach or pattern to this problem?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜