Re: [OBJ-C] Remove Warning for Undocumented Call?
Re: [OBJ-C] Remove Warning for Undocumented Call?
- Subject: Re: [OBJ-C] Remove Warning for Undocumented Call?
- From: Gwynne <email@hidden>
- Date: Sat, 2 Oct 2004 13:49:40 -0400
On Oct 2, 2004, at 1:38 PM, Lance Drake wrote:
There's an undocumented instance method in the Cocoa frameworks for an
NSThing '- (void) _setsomeFlag:(BOOL) flag;'. Why this call is not
documented is another question. When I compile, I get the warning:
`NSThing' may not respond to `-_setsomeFlag:'
I'd like to eliminate the warning I get for this situation without
having to shutoff all warnings for 'incomplete objective-c protocols'.
If I subclass NSThing and provide a call to super for same - the
warning is generated over there. Checking out the Obj-C manual, I'm
thinking I need to create a 'category' - but am not sure. Any ideas?
You have four choices:
1) Do the smart thing and don't use undocumented methods that can go
away between minor system revisions.
2) Live with the warning, since it's there to tell you you're walking
on thin ice.
3) Modify the NSThing header to include a declaration for the method in
question. Even if it's a system header, modifying it changes only what
your code thinks it sees, not what's actually going on. However,
changing system headers is a generally BAD idea as your changes will be
seen by any code that includes those headers and the changes will be
lost next time the header in question (or its containing framework)
gets updated.
4) Typecast your NSThing to (id) before calling the method. The
compiler can't typecheck dynamically typed objects, and therefore won't
issue the warning. You'll still get a warning about an unknown
selector, but you can fix that by declaring an informal protocol, aka a
category on NSObject. This will ONLY work if you cast the object to id.
@interface NSObject (ThePrivateMethodIShouldntBeUsing)
- (void)_setSomeFlag:(BOOL)flag;
@end
I will emphasize again that using undocumented methods is generally an
extremely bad idea. Think long and hard about why you're doing it and
whether there's another way to do what you want done. If there isn't,
then file a bug report with Apple for missing functionality and be
prepared for your code to break in a future system release.
-- Gwynne, key to the Code that runs us all
Email: email@hidden
Web:
http://musicimage.plasticchicken.com/
_______________________________________________
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