Re: Is there a better way to disable a warning? [Solution]
Re: Is there a better way to disable a warning? [Solution]
- Subject: Re: Is there a better way to disable a warning? [Solution]
- From: David Kennedy <email@hidden>
- Date: Wed, 3 May 2006 18:58:14 +0100
Thank you Greg, for a solution to this particular problem...
On 3 May 2006, at 15:23, Greg Hurrell wrote:
El 03/05/2006, a las 15:09, David Kennedy escribió:
Is there a better way of suppressing a warning the the way I am
currently doing it?
I currently have some code which I compile for 10.3.9, that has
been written to use instance methods in 10.4 only if those methods
are available.
The (objective-c) code is like this:
- (void) saveToFile:(NSString *)aFilepath
{
NSString * headerText = [self description];
if ([headerText respondsToSelector:@selector
(writeToFile:atomically:encoding:error:)]) { // Available in Mac
OS X v10.4 and later.
[headerText writeToFile:aFilepath atomically:YES
encoding:NSISOLatin1StringEncoding error:nil]; // The WARNINGS
concern this line
} else if ([headerText respondsToSelector:@selector
(writeToFile:atomically:)]) { // Available in Mac OS X v10.0 and
later. Deprecated in Mac OS X v10.4.
[headerText writeToFile:aFilepath atomically:YES];
}
}
Now this produces the following warnings:
warning: 'NSString' may not respond to '-
writeToFile:atomically:encoding:error:'
warning: (Messages without a matching method signature
warning: will be assumed to return 'id' and accept
warning: '...' as arguments.)
I disable this warning with a per file build setting with -w
But this seems to be overkill. Is there a more specific way to do
this?
For instance, is it possible to suppress a warning for a
particular line or block of code?
and/or is there a specific flag that I've overlooked?
Rather than providing a per-file build setting I prefer to
eliminate the warning by altering the source code itself. In the
example you give you could use a pattern like this (or similar):
SEL selector = @selector(methodWithArg1:arg2:arg3:);
if ([object respondsToSelector:selector])
objc_msgSend(object, selector, arg1, arg2, arg3);
I hadn't come across odjc_msgSend before.
For others who are new to this function, and who are creating
Universal Binaries,
it is worth reading the following in association with the other
documentation about objc_msgSend:
http://developer.apple.com/documentation/MacOSX/Conceptual/
universal_binary/universal_binary_tips/chapter_5_section_23.html
Thanks Again,
Dave
------
David Kennedy (http://www.zenopolis.com)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden