• 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: Is there a better way to disable a warning?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a better way to disable a warning?


  • Subject: Re: Is there a better way to disable a warning?
  • From: Greg Hurrell <email@hidden>
  • Date: Wed, 3 May 2006 16:23:41 +0200

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);

Cheers,
Greg


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

 _______________________________________________
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

  • Follow-Ups:
    • Re: Is there a better way to disable a warning? [Solution]
      • From: David Kennedy <email@hidden>
References: 
 >Is there a better way to disable a warning? (From: David Kennedy <email@hidden>)

  • Prev by Date: Xcode debugger not resetting?
  • Next by Date: File name limited to 31 characters on Mac OS X?
  • Previous by thread: Is there a better way to disable a warning?
  • Next by thread: Re: Is there a better way to disable a warning? [Solution]
  • Index(es):
    • Date
    • Thread