How does one properly redefine self while avoiding the "Multiple methods named ..." warning?
Posted
by Elise van Looij
on Stack Overflow
See other posts from Stack Overflow
or by Elise van Looij
Published on 2010-03-26T16:42:50Z
Indexed on
2010/03/26
16:43 UTC
Read the original article
Hit count: 446
In Apple's The Objective-C Programming Language: Defining a Class the section named "Redifining self" recommends that that class methods allocate and return instances use 'self' only to allocate an instance and then refer only to that instance. Thus, I have a number of subclasses, that have class methods along the lines of:
+ (id)scrollViewWithFrame: (NSRect)rectFrame
{
id newInstance = [[[self alloc] initWithFrame:rectFrame] autorelease];
[newInstance setHasHorizontalScroller: YES];
[newInstance setHasVerticalScroller: YES];
[newInstance setBorderType: NSNoBorder];
[newInstance setAutoresizingMask: (NSViewWidthSizable
| NSViewHeightSizable)];
return newInstance;
}
The above is, of course, a subclass of NSScrollView. Unfortunately, Xcode 3.x all these NSView subclasses now raise warnings: "Warning: Multiple methods named '-setAutoresizingMask' found". I believe it has something to do with GCC 4.2, the settings of which I have not changed.
The warning is correct, of course, since NSView and its various subclasses all implement setAutoresizingMask, but it is also unnecessary. Since they're only warnings, I ignore them but there is a risk that in between the thirty or so unnecessary ones, a really useful warning lurks which I simply don't see. So, what to do? I do want to adhere to good coding practices and I want to build warning-free apps -- how can I do both?
© Stack Overflow or respective owner