caveman_uk said:
I'm assuming you're asking how you'd read the file not how to do it when the apps launched?
If so, it depends on what sort of file it is. Otherwise you make the controller object the app delegate (with [NSApp setDelegate:self] or whatever) and the applicationDidFinishLoading method gets called automatically.
The file is a file I created using NSArchiver its an MDM - MoneyData Manager file. Would I just open the file and populate the array on startup? Or... do you want me to post some code or... see I'm not sure how to do this.
Edit: or do I need to override the openDocument method or create my own open method or what
EDIT2: LET's try this
My document is a Document-based Objective-C Cocoa app. In other words, I can have multiple documents open at the same time.
Now I have class called Transactions which contains information about transactions, in MyDocument.h I define an array for those transactions to store multiple transactions, also in MyDocument there are these two items:
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
[transactionController commitEditing];
return [NSKeyedArchiver archivedDataWithRootObject:transactions];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
NSLog(@"About to read data of type %@", aType);
NSMutableArray *newArray;
newArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if(newArray == nil) {
return NO;
} else {
[self setTransactions:newArray];
return YES;
}
}
Now I have an AppController (AppController.h & .m) so I can open my PreferenceController's (PreferenceController.h & .m) Window (which is a panel), the user can select a file to automatically open when the application starts. I want to be able to open this file, the window to show the file's content (e.g. NSData) and yeah, that's it.