• 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: Method declaration conflict with NSURLConnection.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Method declaration conflict with NSURLConnection.


  • Subject: Re: Method declaration conflict with NSURLConnection.
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Thu, 12 Feb 2004 00:00:37 -0800

Hello...

You will probably want to change your intializer so that the selector is different.

The issue is that alloc always returns type id, so when you do nested message like [[YourClassName alloc] initWithRequest:request delegate:delegate] the initializer is always being sent to an object of type id (and the compiler doesn't know if the id points to a NSURLConnection or an instance of your class.

If you don't change the initializer, every time someone wants to create an instance of your class, they will have to statically type the object returned from alloc:

YourClassName *object = [(YourClassName *)[YourClassName alloc] initWithRequest:request delegate:delegate];

You would probably be much better off making a slight change in the selector ***, maybe like

- (id)initWithXMLRPCRequest:(XMLRPCRequest *)request delegate:(id)delegate;


For more info, see the Archives:

"Multiple declarations for method length"
http://cocoa.mamasam.com/COCOADEV/2003/12/2/80393.php

"Warning when using NSSplitView"
(aka "Warning when using NSSplitView (multiple declerations for method 'isVertical'")
http://cocoa.mamasam.com/COCOADEV/2004/01/1/80671.php


Hope that helps,

Louis

*** Technically it might be possible to redeclare +alloc in your classes header file to return (YourClassName *) instead of (id), but the convention is to always return id from alloc and initializers, and there's a possibility that doing so could cause even worse / more annoying problems. Perhaps someone else on the list will be able to tell you for sure...



I'm writing an XML-RPC framework that follows a request, connection,
response pattern. The developer creates the request, supplies a connection
with a request, then returns a response. A lot of the inner workings of
these classes rely on the NSURLRequest and NSURLConnection classes. All is
fine until, however, I create an instance of my connection class. It just so
happens that my connection class and the NSURLConnection class have the same
init method, with slight differences...

- (id)initWithRequest: (XMLRPCRequest *)request delegate: (id)delegate;

I wouldn't think this should be a problem, but it is. When I write code that
uses this class, and initializes it, the compiler thinks I am making a call
to NSURLConnection's method, not my own. A strange behavior, considering
everything has been declared properly, and I'm not doing anything crazy. I
don't know what the problem could be, any ideas?

Regards,
Eric Czarny
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: RE: Spinning wait cursor in COCOA
  • Next by Date: prefs stopped saving.
  • Previous by thread: Re: Method declaration conflict with NSURLConnection.
  • Next by thread: Problem with CFTreeAppendChild ...
  • Index(es):
    • Date
    • Thread