Note that there are some explanatory texts on larger screens.

plurals
  1. POObj-C Private Method Compiler Warnings
    primarykey
    data
    text
    <p>Private methods are a useful construct to keep code organised within class boundaries. An example being the organisation of long winded Quartz 2d instructions in a custom UIView subclass. I am able to include such methods in '.m' files with no declaration in '.h'. A working example from a UIView subclass '.m' file reads:</p> <pre><code>-(void)DoSomethingPrivate { //Not declared in interface NSLog(@"Does this print a private function?"); } - (id)initWithFrame:(CGRect)frame //Declared in inherited interface { self = [super initWithFrame:frame]; if (self) { [self DoSomethingPrivate]; //Error: 'Instance method not found' } //... but it works anyway. return self; } </code></pre> <p>My problem is that the compiler generates the warning "Instance method '-DoSomethingPrivate' not found (return type defaults to 'id')" on the line calling the private function. I'm aware from responses to <a href="https://stackoverflow.com/questions/5293129/how-do-i-fix-this-warning-method-not-found-return-type-defaults-to-id">this question</a> that I can use a 'no name' interface category to 'hide' private method declarations. </p> <p>However, when I review Apple sample code <a href="http://developer.apple.com/library/ios/#samplecode/SimpleStocks/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011103" rel="nofollow noreferrer">SimpleStocks</a>, file "<a href="http://developer.apple.com/library/ios/#samplecode/SimpleStocks/Listings/SimpleStocks_SimpleStockView_m.html#//apple_ref/doc/uid/DTS40011103-SimpleStocks_SimpleStockView_m-DontLinkElementID_11" rel="nofollow noreferrer">SimpleStockView.m</a>", it contains a private function which is neither declared in a no-name category interface, nor does it generate compiler warnings:</p> <pre><code>//Private Function - (void)drawRadialGradientInSize:(CGSize)size centeredAt:(CGPoint)center { ... } //Is called by this function... - (UIImage *)patternImageOfSize:(CGSize)size { ... //The next line doesn't generate any warnings! [self drawRadialGradientInSize:size centeredAt:center]; ... } </code></pre> <p>I'd be grateful if anyone can shed any light on how Apple's sample-code private-methods appear to escape compiler checks, so I may avoid having to maintain a 'no-name' category header with all my private methods.</p> <p>Many thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload