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 > (Obj-C) One of ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 3733 of 3795
Post > Topic >>

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

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

One of these things consistently pukes...

Forgive blown line ends in the code that follows... It's cut-n-pasted 
directly from the project, 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.

In both cases, "TheData" (the "NSData" version that actually 
participates in the "read from the URL" operation) *SHOULD*, according 
to my understanding based on reading the API help, get stuffed with the 
contents of MyURL. In the first version, it does. In the second, it gets 
filled with random garbage. 

The second is clearly less complex (A whole two statements, versus 
five), but doesn't appear to perform "as advertised"...

Why??? 
 

Code follows...

#define TESTING 1

#if TESTING //   ********** First version
 - (void)GetRawData
{
   NSError *TheError = [NSError alloc];
   NSURLResponse *TheResponse = [NSURLResponse alloc]; // We don't care 
about it, but we need it to make the NSURLConnection call
   NSURL *MyURL = [NSURL 
URLWithString:@[EMAIL PROTECTED]
"http://moneycentral.msn.com/investor/market/exchangerates
..aspx?selRegion=1&selCurrency=1"];
   NSURLRequest *urlRequest = [NSURLRequest requestWithURL:MyURL];   
   NSData *TheData = [NSURLConnection sendSynchronousRequest:urlRequest 
returningResponse:&TheResponse error:&TheError];

   printf("TheData:\n");
   HexDump((UInt8 *)[TheData bytes], [TheData length], 1);
   [Buffer setData:TheData];
   printf("The Buffer:\n");
   HexDump((UInt8 *)[Buffer mutableBytes], [Buffer length], 1);
}
#else   // *********** Second version....
- (void)GetRawData
{
   NSURL *MyURL = [NSURL 
URLWithString:@[EMAIL PROTECTED]
"http://moneycentral.msn.com/investor/market/exchangerates
..aspx?selRegion=1&selCurrency=1"];
   NSData *TheData = [NSData dataWithContentsOfURL:MyURL];

   printf("TheData:\n");
   HexDump((UInt8 *)[TheData bytes], [TheData length], 1);
   [Buffer setData:TheData];
   printf("The Buffer:\n");
   HexDump((UInt8 *)[Buffer mutableBytes], [Buffer length], 1);
}
#endif

-- 
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 Sun Jul 6 17:44:11 CDT 2008.