Re: Handling Multiple Document Types
Re: Handling Multiple Document Types
- Subject: Re: Handling Multiple Document Types
- From: Matt Mashyna <email@hidden>
- Date: Mon, 9 Jul 2007 09:08:26 -0400
On Jul 8, 2007, at 10:55 PM, acoolie wrote:
I have a NSDocument application which should handle two types of
document.
One document will be an actual file and the other will not. My current
working solution is to determine which type of document the
document is in
MyDocument, storing it in an instance variable, then using a simple
if-else
in all methods to run different code for each document type.
I figured that it might be easier to instead have MyDocument, then
two subclasses of MyDocument, DocumentA and DocumentB. MyDocument
will determine if it should be DocumentA or DocumentB in any method
(not necessarily init). I am not quite sure how I would go about this.
I figure using self = [[DocumentA alloc] init]; would be a bad idea
since
DocumentA-init would call -init on the MyDocument again too.
After searching around a little bit, I found some code for returning a
subclass of the class in init or in a factory class. This solution
sounds
reasonable but my problem is since I am using the NSDocument
architecture
the -init method is called before the document is actually loaded in
readFromData: or readFromURL:
I have a feeling this solution is entirely unnecessary and there is
either a
much easier solution to this or my current solution is fine. Any
help would
be appreciated, I am not very attached to my current method so if
you can
solve my issue without solving the subclass problem that would be
fine.
-ACoolie
_______________________________________________
I have apps that open files that are several different types. You
just have to associate classes with file extensions and file types in
the Properties pane of the Target Settings. This pane will get your
plist set up properly.
I have one app that opens a document that is the same class but has
slightly different representations on Mac OS X, OS 9 and Windows. I
override
- (BOOL)loadFileWrapperRepresentation:(NSFileWrapper *)wrapper ofType:
(NSString *)docType
and look at the the docType to decide what to do with it. The docType
is the name in the first column of the Document Properties pane.
Then when it's time to save them I do the reverse by overriding
- (BOOL)writeWithBackupToFile:(NSString *)fullDocumentPath ofType:
(NSString *)docType saveOperation:(NSSaveOperationType)saveOperationType
Matt
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden