Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: (Obj-C) One...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 3733 of 3882
Post > Topic >>

Re: (Obj-C) One of these things is not like the other...

by Don Bruder <dakidd@[EMAIL PROTECTED] > May 6, 2008 at 06:57 PM

In article <uce-D3811F.18522906052008@[EMAIL PROTECTED]
>,
 Gregory Weston <uce@[EMAIL PROTECTED]
> wrote:

> In article <6d6dnSly0L5RWr3VnZ2dnUVZ_qKgnZ2d@[EMAIL PROTECTED]
>,
>  Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> 
> > One of these things consistently pukes...
> > 
> > Forgive blown line ends in the code that follows... It's cut-n-pasted 
> > directly from the project,
> 
> Which puts you one step ahead of half the people who ask for help.
> 
> > and the newsreader isn't too good at wrapping Objective-C! 
> > 
> > In the code that follows, if "TESTING" = 1, I get the expected result:

> > The instance variable (declared as "NSMutableData *Buffer;" in my .h 
> > file) Buffer comes back filled with the HTML from MyURL.
> > 
> > If "TESTING" !=1, Buffer comes back filled with random garbage.
> > 
> > Likewise, when the first version gets used, the local NSData (Note NOT

> > mutable) TheData variable is loaded with the HTML that comes from
MyURL, 
> > but when the second version is used, TheData contains random garbage.
> 
> My first thought is that you're sort of overcomplicating things or 
> reading things backwards. The issue is that [NSData 
> dataWithContentsOfURL:MyURL] is not returning what you expect.

Aye - That it isn't. And I can't figure out why.
 
> Everything after that - in particular the fact that Buffer comes out 
> wrong - is an obvious result.

Pretty much...

> 
> Out of curiosity, are the first two bytes that you get back in the 
> second case 1F and 8B?

Uh, lemme look...

Indeed - hexdumping TheData shows me a 1f 8b sequence at the start...

> 
> If so, you appear to have run across a bug that was introduced 4+ years 
> ago:
> 
> <http://www.cocoabuilder.com/archive/message/cocoa/2004/3/22/102280>

Hrrrmmm... Color me bitten. That sure sounds like the symptoms.
And, unfortunately, the "workaround" is to use the method I used in 
Version 1... That's some catch, that Catch-22! :) 

> 
> BTW: You really should avoid using synchronous downloads if you can.

From what I can see, I'd tend to agree - which is why I was trying to 
hook into the "dataWithContentsOfURL" method. Or is that synchronous, 
too? 

Version 1 is the original, synchronous, "works fine" version.
Version 2 is my attempt to get away from the explicitly synchronous 
thing, and let the transfer happen in the background - Although now that 
I think about it further, dataWithContentsOfURL MUST be synchronous - So 
is there a simple, non-sync way of doing the deed? I envision a fantasy  
to the tune of "Here's a URL and a callback. Holler via the callback 
when you've got the needed data so we can proceed"
> 
> BTW2: In case one, these two lines are wrong:
> 
>    NSError *TheError = [NSError alloc];
>    NSURLResponse *TheResponse = [NSURLResponse alloc];
> 
> You should never alloc without a subsequent init.... More im****tantly, 
> in the specific way you're using them, you should initialize the 
> variables to nil instead of allocating space; they're output arguments. 
> What you've got leaks.

Ah, OK... Something like this:

NSError *TheError = nil;

etc?

I thought I had to have an actual NSError/NSURLResponse, etc available 
before I made the call. Guess that's what thinkin' does for me :)

-- 
Don Bruder - dakidd@[EMAIL PROTECTED]
 - If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info
 




 6 Posts in Topic:
(Obj-C) One of these things is not like the other...
Don Bruder <dakidd@[EM  2008-05-06 14:04:10 
Re: (Obj-C) One of these things is not like the other...
Gregory Weston <uce@[E  2008-05-06 18:52:29 
Re: (Obj-C) One of these things is not like the other...
Don Bruder <dakidd@[EM  2008-05-06 18:57:46 
Re: (Obj-C) One of these things is not like the other...
David Phillip Oster <o  2008-05-06 20:27:56 
Re: (Obj-C) One of these things is not like the other...
David Phillip Oster <o  2008-05-06 20:33:31 
Re: (Obj-C) One of these things is not like the other...
David Phillip Oster <o  2008-05-06 23:38:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:25:18 CST 2008.