• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Newbie question: NSDocument and standard file formats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie question: NSDocument and standard file formats


  • Subject: Newbie question: NSDocument and standard file formats
  • From: Andrew Ebling <email@hidden>
  • Date: Sun, 25 Nov 2007 15:25:39 +0000

Hello,

I'm trying to write my first Cocoa document-based application, which will manipulate PNG images. At this stage, I'm trying to write an NSDocument subclass which will load data from a PNG image file and create an instance of NSImage, which will then be handed to a View class for display.

However, the existing "plumbing" provided by AppKit seems to assume that you are trying to read in documents which you have previously written out (i.e. proprietary formats which you have invented just for your application). What I want to do is read an existing file format:

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error: (NSError **)outError
{
NSImage *img = [[NSImage alloc] initWithData:data];
[imageView setImage:img];
[img release];


    	return YES;
}

However, that naive code does not work, because the data contained in the NSData does not appear to be in a format that NSImage understands.

So I went digging in:

ADC Home > Reference Library > Guides > Cocoa > Design Guidelines > Document-Based Applications Overview > The Roles of Key Objects in Document-Based Applications

And read the following:

"When the user chooses Open from the File menu, theNSDocumentController object displays the Open panel, gets the user’s selection, finds the NSDocument subclass for the file (based on its document type information), allocates an instance of this class, and initializes the object and loads document data by invoking the NSDocument method initWithContentsOfURL:ofType:error:"

So my question is, without subclassing NSDocumentController (which I understand you are not supposed to do), how do I tell NSDocumentController to simply hand me back an instance of NSImage? Or is it even already doing this for me and all I have to do is get the class out of NSData? If so how?

Thank you for your patience with this basic question. At the moment I feel like I'm falling down the gap between finishing a book on Cocoa (Hillegass book in my case) and being confident/competent enough to make progress on a genuinely useful application.

best regards,

Andrew

_______________________________________________

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


  • Follow-Ups:
    • Re: Newbie question: NSDocument and standard file formats
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: How to get window title bar font ^size^ ?
  • Next by Date: Re: NSWindow - Sheets - background alpha value
  • Previous by thread: Developer for SOAP
  • Next by thread: Re: Newbie question: NSDocument and standard file formats
  • Index(es):
    • Date
    • Thread