• 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: Selector Not Recognized
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selector Not Recognized


  • Subject: Re: Selector Not Recognized
  • From: Chris Suter <email@hidden>
  • Date: Wed, 12 Jul 2006 08:40:54 +1000


On 12/07/2006, at 8:30 AM, David Alter wrote:

Sorry about that. That was not the example I intended to send. Lets see if this does a better job of explaining this.


//The interface for the parent class @interface MyParent : NSObject { int somedata }

@end

//The interface for the sub class
@interface MySub : MyParent {
}
- (int) getSomeDataPlusOne; // This will access somedata from the parent class add one to it and return it.


@end


//Some code some place

	//Make an instance on MyParent
	MyParent * parent =  [[MyParent alloc] init];

	//Cast MyParent into a pointer of MySub.
	MySub * sub = (MySub *) parent;

//Access a method of MySub.
int val = [sub getSomeDataPlusOne]; // It chokes here with "selector not recognized"


The key here is the pointer is a pointer to MyParent, NOT MySub. Sense MySub has not instance variables can I cast it into MyParent. If not what is the suggested way of doing things.

Thanks again for the help

-dave

All objective-C calls are resolved at runtime. Casts don't make any difference to which methods get called.


If you want to override a method in an existing class you can use categories or poseAsClass. Read the documentation for poseAsClass in NSObject.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >Selector Not Recognized (From: David Alter <email@hidden>)
 >Re: Selector Not Recognized (From: "Shawn Erickson" <email@hidden>)
 >Re: Selector Not Recognized (From: David Alter <email@hidden>)

  • Prev by Date: Re: list of invar names
  • Next by Date: Re: Re: Selector Not Recognized
  • Previous by thread: Re: Selector Not Recognized
  • Next by thread: Re: Re: Selector Not Recognized
  • Index(es):
    • Date
    • Thread