Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Usefulness of -Wstrict-selector-match



Since ObjC dispatches everything at runtime regardless of weather you use a cast or not, I personally have no issue with giving the compiler a hint. I think the only reason this is considered "bad practice" is because in a statically typed language it would be. But ObjC is not statically typed, and the only problem the cast could potentially make is outside our control anyway, so casting seems like the best alternative.

I don't use strict selector matching, since argument passing bugs are extremely rare (outside the scripting bridges) and easily spotted with a debugger. I use my own extensions to the mactypes types ([US]Int(4|8| 16|32|64) and [US]IntP which I define) to avoid rounding troubles in my own code (which needs to work with ObjC "1.0")

Does anyone have a different system that they find works well?

On Apr 18, 2008, at 11:01 AM, Sean McBride wrote:

Jonathan,

Thanks for your reply. The cast would of course work, but seems icky
since the variable is not an NSArray, it could be an NSSet,
NSDictionary, etc. The snippit I gave is of course an example, but the
real code is in an NSValueTransformer subclass' "- (id)transformedValue:
(id)value" method, hence my use of 'id'.


I guess my real question is: are people using -Wstrict-selector- match or
do most of you run into annoying warnings like below?


Cheers,

Sean


On 4/17/08 6:20 PM, Jonathan deWerd said:

Cast the array to an NSArray*. Better, define it as one in the first
place. Use id as little as possible.

On Apr 17, 2008, at 12:26 PM, Sean McBride wrote:

Hi all,

Given:

-------
#import <Cocoa/Cocoa.h>

int main (void)
{
	id array_or_set = nil;
	NSUInteger x = [array_or_set count];
	(void)x;
	
	return 0;
}
-------

and compiling like so:

$ gcc -Wstrict-selector-match -framework Cocoa ~/Desktop/
count_warning.m

I get:

warning: multiple methods named '-count' found
/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h: 15:
warning: using '-(NSUInteger)count'
/System/Library/Frameworks/QuartzCore.framework/Headers/CIVector.h: 59:
warning: also found '-(size_t)count'


How do others deal with this?  I find -Wstrict-selector-match often
useful, but cases like these are problematic.

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Objc-language mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: h

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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

References: 
 >Usefulness of -Wstrict-selector-match (From: "Sean McBride" <email@hidden>)
 >Re: Usefulness of -Wstrict-selector-match (From: Jonathan deWerd <email@hidden>)
 >Re: Usefulness of -Wstrict-selector-match (From: "Sean McBride" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.