• 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
initWithContentsOfURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

initWithContentsOfURL


  • Subject: initWithContentsOfURL
  • From: Gary C Martin <email@hidden>
  • Date: Wed, 8 Aug 2001 15:14:44 +0100

As another newcomer to Cocoa here, I've been bouncing about the documentation trying to get the the initWithContentsOfURL method for NSImage to actually return something other than nil objects.

Apologies if I'm being particularly thick but below is a selector method I thought should work to initialize (NSImage *)myImage from a NSURL ready for use, however it always returns as a nil object:

- (void)URLResourceDidFinishLoading:(NSURL *)sender
{
// this always returns nil :o(
NSImage *myImage = [[[NSImage alloc] initWithContentsOfURL:sender] autorelease];

// do other things with myImage here
}

Now I have managed to get the job done with an alternative route that works just fine (see below). It's just that I'd like to get my head around why the above initWithContentsOfURL code fails. Here's a working method:

- (void)URLResourceDidFinishLoading:(NSURL *)sender
{
// correctly returns a valid NSImage
NSImage *myImage = [[[NSImage alloc] initWithData:[sender resourceDataUsingCache:YES]] autorelease];

// do other things with myImage here
}

Oooh, here's the method that kicks off the initial loading attempt:

- (void)loadImageWithURL: (id)sender
{
// sample uk weather map URL
NSURL *myURL = [NSURL URLWithString:@"http://eur.yimg.com/w/eu/english/outlook/uk24c.jpg";];
[myURL loadResourceDataNotifyingClient:self usingCache:YES];
}

Thanks for any guiding words.

Regards,
Gary C Martin


  • Prev by Date: Re: It is time for me to take a decision.
  • Next by Date: Re: It is time for me to take a decision.
  • Previous by thread: overriding cocoa classes globally
  • Next by thread: Reading raw bytes
  • Index(es):
    • Date
    • Thread