Quite nice, thanks GG. -koko
On Jul 8, 2012, at 3:01 PM, Greg Guerin wrote: > koko wrote: > >> I have 29 file types and wanted to get away from the if or switch to open >> them and let NSDocument pick the right class for me. >> >> As I understand it, an Item in the Document types array of the plist >> contains and entry for an NSDocument class. >> >> And yes, each type has a unique extension (possibly multiple). I.e. type >> phobia has extensions pho, pho12, pho15 all mapped to NSDocument subclass >> MYPhobia. > > > Use an NSDictionary. The key is the file extension. The value is the > subclass name, or the actual Class object. Cost is one dictionary lookup. > Plus it's extensible, and can be revised without altering code. > > You can also add a level of indirection. The key is still file extension, > but the value is a number (int). Use the number as an index into an NSArray > of classname strings, or the actual Class objects. > > The dictionary and/or array can be stored as plists in your app's Resources > sub-dir. > > -- GG > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net > > This email sent to k...@highrolls.net > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com