• 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
RE: CodeWarrior and Objective-C warnings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: CodeWarrior and Objective-C warnings


  • Subject: RE: CodeWarrior and Objective-C warnings
  • From: Jeff Laing <email@hidden>
  • Date: Thu, 2 Dec 2004 12:21:17 +1100

Clearly, the compiler can't see that though.
 
The original request was how to silence a warning about code that the compiler thought might cause problems, since it could not see the semantic content.  Switching to using explicit casts would solve that problem, albeit at a change to the way you've coded it.
 
My preference in this case is to test to ensure that I know *what* came back, not just "what its prepared to respond to".  The latter is similiar to Apple's answer when people ask "what version number of Quicktime should I test for if I want feature X", and in that case I think its the right approach.  Don't ask for version numbers, ask about the feature you want.
 
In this case, however, I believe what you really want is "for an HTTP response to have come back", and not for "something that has a status code".  But thats me.
 
Neither approach is wrong - its all about paranoia, trying to future-proof, guard against all possible consequences that *might* come back out of an API.
 
-----Original Message-----
From: John Stiles [mailto:email@hidden]
Sent: Thursday, December 02, 2004 12:12 PM
To: Jeff Laing
Cc: email@hidden
Subject: Re: CodeWarrior and Objective-C warnings

Well, that would make sense if I had asked for a mail:// URL, but I didn't.



On Dec 1, 2004, at 5:11 PM, Jeff Laing wrote:


I was thinking more of someone passing back say NSMAILURLResponse where statusCode might contain SMTP error codes?

(Not that I know there is such a thing as NSMAILURLResponse, but it seems possible that in an infinite number of futures where the infinite number of monkeys keep banging on the internet, at least ONE of those futures might result in such a beast, or some other protocol as yet unheard of)

-----Original Message-----

From: John Stiles [mailto:email@hidden]

Sent: Thursday, December 02, 2004 12:06 PM

To: Jeff Laing

Cc: email@hidden

Subject: Re: CodeWarrior and Objective-C warnings



I can test for that class, but I don't know... it seemed a little more resilient to check if the object responds to the selector I want. OTOH, I can't imagine that the definition of a status code for an HTTP request will change in the future... that just seems a little too far-fetched to concern myself with. 200 is OK, 404 is file not found, etc., now and forever :)





On Dec 1, 2004, at 5:02 PM, Jeff Laing wrote:





I think I'd be testing for that class and casting, rather than testing that that message was processed.  After all, someone may introduce a different NSURLResponse subclass that responds to that message in a different way, or at least in a way you weren't expecting...


-----Original Message-----


From: John Stiles [mailto:email@hidden]


Sent: Thursday, December 02, 2004 11:56 AM


To: Jeff Laing


Cc: email@hidden


Subject: Re: CodeWarrior and Objective-C warnings





"statusCode" isn't mine, it's a NSHTTPURLResponse selector. The NSURLResponse being sent to the callback is actually an NSHTTPURLResponse--at least, that's the plan :)







On Dec 1, 2004, at 4:52 PM, Jeff Laing wrote:








My guess would be to make your statusCode part of a formal protocol and then use an explicit cast once you are sure that response implements the protocol.




Alternately, if you are going to use respondsToSelector: to test viability, you could use performSelector: to actually invoke it.




-----Original Message-----




From: John Stiles [mailto:email@hidden]




Sent: Thursday, December 02, 2004 11:43 AM




To: email@hidden




Subject: CodeWarrior and Objective-C warnings







I have code that looks like this








- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response






{






        if( [response respondsToSelector:@selector(statusCode)] )






        {






                if( [response statusCode] == 200 )






                {






                        // stuff






                }






        }






}








When I call [response statusCode] in the code above, CodeWarrior warns that "receiver cannot handle this message." Obviously this was taken care of on the previous line, but I can see how a compiler might not understand this :) How can I placate the compiler and silence the warning (other than disabling warnings)?

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: CodeWarrior and Objective-C warnings
  • Next by Date: Re: cross development on Jaguar
  • Previous by thread: Re: CodeWarrior and Objective-C warnings
  • Next by thread: Do something before creating a new file
  • Index(es):
    • Date
    • Thread