Cocoanetics / DTCoreText

Methods to allow using HTML code with CoreText
BSD 2-Clause "Simplified" License
6.35k stars 1.18k forks source link

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

Closed ghost closed 12 years ago

ghost commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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

ghost commented 12 years ago

Warnings fixed! Zero warnings in XCode 4.4 DP2 now!

odrobnik commented 12 years ago

Hooray! Thanks for your help!