Well I was really inspired to make an app after firstly hearing about some Mac Indie Developer tales and downloading some Safari plug-ins, so I decided to install Xcode.
I've made a basic little Word Processor that I planned to use instead of TextEdit as I can't afford iWork, yet want something less depressing than TextEdit (It's quite a dull app, really xD), so I set off on making an app by following tutorials online.
See, I'm a Movie Maker and musician who so happened to start web development to promote my stuff. This led me to use Leopard's Dashcode to make some widgets - which was an enjoyable experience to say the least (Particularly because I now know a heck of a lot about HTML, Javascript, etc.)... and after realizing how easy Apple had made it to develop widgets, I thought I'd give Software Development a go. Nothing huge but this is just early days (I do have some crazily ambitious plans for this small text editor I'm working on, I must say )
But before the exciting, innovative features can come along, I must get the bear essentials working first... and right now, I'm stuck on saving.
I followed the instructions on Apple's site but can't make heads nor tales of it.
Basically, I have this:
That's my file called MyDocument.m which I am assuming is the same as "NSDocument" since that's what worked with the file types... I think (and nothing comes up when I search NSDocument in Xcode).
Xcode says that "[fileAttributes setObject:[NSNumber numberWithUnsignedInt:'kMyAppCreatorCode']" (in both places) is "Character constant too long for it's type" - and I have no idea what that means. Whatever it is, it means I can't save files, that's for sure.
All help appreciated and I'll put your name in the App credits.
I've made a basic little Word Processor that I planned to use instead of TextEdit as I can't afford iWork, yet want something less depressing than TextEdit (It's quite a dull app, really xD), so I set off on making an app by following tutorials online.
See, I'm a Movie Maker and musician who so happened to start web development to promote my stuff. This led me to use Leopard's Dashcode to make some widgets - which was an enjoyable experience to say the least (Particularly because I now know a heck of a lot about HTML, Javascript, etc.)... and after realizing how easy Apple had made it to develop widgets, I thought I'd give Software Development a go. Nothing huge but this is just early days (I do have some crazily ambitious plans for this small text editor I'm working on, I must say )
But before the exciting, innovative features can come along, I must get the bear essentials working first... and right now, I'm stuck on saving.
I followed the instructions on Apple's site but can't make heads nor tales of it.
Basically, I have this:
Code:
#import "MyDocument.h"
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return nil;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
// You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return YES;
}
[B]const OSType kMyAppCreatorCode = 'ttxt';
- (NSDictionary *)fileAttributesToWriteToURL:(NSURL *)absoluteURL
ofType:(NSString *)typeName
forSaveOperation:(NSSaveOperationType)saveOperation
originalContentsURL:(NSURL *)absoluteOriginalContentsURL
error:(NSError **)outError
{
NSMutableDictionary *fileAttributes =
[[super fileAttributesToWriteToURL:absoluteURL
ofType:typeName forSaveOperation:saveOperation
originalContentsURL:absoluteOriginalContentsURL
error:outError] mutableCopy];
[fileAttributes setObject:[NSNumber numberWithUnsignedInt:'kMyAppCreatorCode']
forKey:NSFileHFSCreatorCode];
[fileAttributes setObject:[NSNumber numberWithUnsignedInt:'kMyDocumentTypeCode']
forKey:NSFileHFSTypeCode];
return [fileAttributes autorelease];
}[/B]
@end
That's my file called MyDocument.m which I am assuming is the same as "NSDocument" since that's what worked with the file types... I think (and nothing comes up when I search NSDocument in Xcode).
Xcode says that "[fileAttributes setObject:[NSNumber numberWithUnsignedInt:'kMyAppCreatorCode']" (in both places) is "Character constant too long for it's type" - and I have no idea what that means. Whatever it is, it means I can't save files, that's for sure.
All help appreciated and I'll put your name in the App credits.