Re: Handling Multiple Document Types
Re: Handling Multiple Document Types
- Subject: Re: Handling Multiple Document Types
- From: David Phillip Oster <email@hidden>
- Date: Mon, 9 Jul 2007 08:11:52 -0700
At 6:35 AM -0700 7/9/07, email@hidden 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.
You can create a subclass of NSDocumentController , instantiate it in
your MainMenu.nib, and give it the following overrides:
@implementation MyDocumentController
- (NSString *)typeForContentsOfURL:(NSURL *)inAbsoluteURL
error:(NSError **)outError {
if ([... my predicate here...:inAbsoluteURL]) {
return @"MyDocument1";
} else if ([... my predicate2 here...:inAbsoluteURL]) {
return @"MyDocument2";
}
return nil;
}
- (Class)documentClassForType:(NSString *)typeName {
if ([... my predicate here...:typeName]) {
return [MyDocument1 class];
} else if ([... my predicate2 here...:typeName]) {
return [MyDocument2 class];
}
return nil;
}
@end
documentClassForType: will be called for making new, untitled
documents, while typeForContentsOfURL: will be called for opening
existing files, etc.
_______________________________________________
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