Skip to content

typedef UIColor DTColor; && @class DTColor; cause compiler warning #147

Closed
ghost opened this Issue Mar 19, 2012 · 6 comments

2 participants

@ghost
ghost commented Mar 19, 2012

Hi there,

I'm using XCode4.4DP2. Anyway the warnings below won't show up in XCode4.3.1.

/Users/zhaojianyin2012/Dev/DTCoreText/Core/Source/NSScanner+HTML.h:11:1: Redefinition of forward class 'DTColor' of a typedef name of an object type is ignored

/Users/zhaojianyin2012/Dev/DTCoreText/Core/Source/DTHTMLElement.h:13:1: Redefinition of forward class 'DTColor' of a typedef name of an object type is ignored

/Users/zhaojianyin2012/Dev/DTCoreText/Core/Source/NSScanner+HTML.h:11:1: Redefinition of forward class 'DTColor' of a typedef name of an object type is ignored

/Users/zhaojianyin2012/Dev/DTCoreText/Core/Source/NSString+CSS.h:9:1: Redefinition of forward class 'DTColor' of a typedef name of an object type is ignored

@odrobnik

Maybe you can come up with a better way to do that. I am only doing this typedef because I need DTColor to be UIColor on iOS and NSColor on Mac.

Maybe there's another order of imports and typedef that fixes this warning?

@ghost
ghost commented Mar 19, 2012

Hi,
I'm not sure, maybe separate the API by using this?

#if TARGET_OS_IPHONE 
#elif TARGET_OS_MAC 
#endif

But this will split all related code and probably not a good idea.

Or add another head file to contain all the forward decl, like DTCoreTextForwardDecl.h and add it to the .pch file?
Maybe just don't bother with this warning, seems not a big deal.

@zwaldowski

All Objective-C compilers as far as I know all support the @compatability_alias directive, used like @compatibility_alias DTColor UIColor. A bit more robust than a #define, more compatible than a subclass, safer than casting to id, and more language-safe than a typedef. It's all up to you, though.

EDIT: The 4.4 compiler also seems to crack down some on casts for string formats; at DTCSSListStyle.m:246, 0x%x should be %p and in NSString+HTML.m:689 %C should be %d, according to this.

@odrobnik

please test if the two fixes I pushed are fixing the issue.

@ghost
ghost commented Mar 21, 2012

Warnings fixed!
Zero warnings in XCode 4.4 DP2 now!

@ghost ghost closed this Mar 21, 2012
@odrobnik

Hooray! Thanks for your help!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.