• 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: Why would a defined selector not be found at runtime?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why would a defined selector not be found at runtime?


  • Subject: Re: Why would a defined selector not be found at runtime?
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 12 May 2005 11:06:31 -0700


On May 12, 2005, at 10:53 AM, Ken Tozier wrote:

Allocating like this:

NSDisclosureButtonCell    *result        = [[NSDisclosureButtonCell alloc] initWithControlSize: inControlSize];


fails with the exact same error message as:

NSDisclosureButtonCell    *result        = [NSDisclosureButtonCell alloc];


 // next line shows a valid object in "result"

NSLog(@"result = %@", result);


// chokes here

[result  initWithControlSize: inControlSize];


error log:

*** -[NSDisclosureButtonCell initWithControlSize:]: selector not recognized



I've read in multiple places that you should never split it up like you're doing. It should always be alloc/init'd together.



Hadn't heard that. Although I never alloc/init in two steps unless there is a problem and I want to see what's happening...



The primary reason you should not alloc/init in two steps is that the init may return a different object.  It can be done correctly--the correct code would be

NSDisclosureButtonCell *result = [NSDisclosureButtonCell alloc];
NSLog(@"result = %x", result);
result = [result initWithControlSize:inControlSize];

but the quoted code shows some of the obvious errors that make this a bad idea:  (1) the return value of initWithControlSize: should replace result, but does not; (2) you cannot in general send any message other than an initializer to an alloc'd but uninitialized object, so you should not use %@ with result here.

Douglas Davidson

 _______________________________________________
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

  • Follow-Ups:
    • Re: Why would a defined selector not be found at runtime?
      • From: Andy Lee <email@hidden>
    • Re: Why would a defined selector not be found at runtime?
      • From: Ken Tozier <email@hidden>
References: 
 >Why would a defined selector not be found at runtime? (From: Ken Tozier <email@hidden>)
 >Re: Why would a defined selector not be found at runtime? (From: Ricky Sharp <email@hidden>)
 >Re: Why would a defined selector not be found at runtime? (From: Ken Tozier <email@hidden>)
 >Re: Why would a defined selector not be found at runtime? (From: SA Dev <email@hidden>)
 >Re: Why would a defined selector not be found at runtime? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Why would a defined selector not be found at runtime?
  • Next by Date: Re: Why would a defined selector not be found at runtime?
  • Previous by thread: Re: Why would a defined selector not be found at runtime?
  • Next by thread: Re: Why would a defined selector not be found at runtime?
  • Index(es):
    • Date
    • Thread