CHCSVParser icon indicating copy to clipboard operation
CHCSVParser copied to clipboard

Two warnings when building using XCode 7 Beta 5

Open yoasha opened this issue 10 years ago • 16 comments

  • 'CHCSVParser' class: Method override for the designated initializer of the superclass '-init' not found
  • 'CHCSVWriter' class: Method override for the designated initializer of the superclass '-init' not found

I realize that these warnings are not affecting the functionality... However, it would be really nice having zero warnings in my project.

Thank you for this great project!

yoasha avatar Aug 23 '15 15:08 yoasha

I am getting the same issue. Had you figured this one out yourself by any chance?

JaxMyers avatar Sep 13 '15 21:09 JaxMyers

I didn't really try to handle these warnings as they are harmless. I am also sure that this issue will be targeted by the project owner when he will get to it.

yoasha avatar Sep 14 '15 07:09 yoasha

I just checked and this warning doesn't occur with the HEAD version of CHCSVParser.

thomasaw avatar Sep 16 '15 14:09 thomasaw

Definitely still getting these warnings with the latest code on the master branch today. They are the only warnings in my project. It would be very nice to have them fixed.

jeffdgr8 avatar Sep 17 '15 21:09 jeffdgr8

You're right. This is occurring with Xcode 7. A related warning with Xcode 6.4 was fixed by moving to HEAD.

thomasaw avatar Sep 18 '15 01:09 thomasaw

This SO link seems to explain what's causing the warning (http://stackoverflow.com/a/24565513/45813). If you are very concerned about removing the warnings your best option now is to suppress them: In your project:

  1. Edit the build settings for your the CHCSVParser target.
  2. Search for "Other warning flags".
  3. Add -Wno-objc-designated-initializers

You could do turn it off on a per file basis as well as the link explains

bakwarte avatar Sep 18 '15 04:09 bakwarte

You can disable the warnings by a adding this at the top of your CHCSV.m and CHCSV.h files just before @interface.

#ifdef __IPHONE_8_0 // suppress these errors until we are ready to handle them //#pragma message "Ignoring designated initializer warnings" #pragma clang diagnostic ignored "-Wobjc-designated-initializers" #else // temporarily define an empty NS_DESIGNATED_INITIALIZER so we can use now, // will be ready for iOS8 SDK #define NS_DESIGNATED_INITIALIZER #endif

JaxMyers avatar Sep 22 '15 18:09 JaxMyers

Dave has recently checked in changes to a 3.0.0 branch of this project. The 3.0.0 version is Swift-based and doesn't have this warning.

thomasaw avatar Sep 27 '15 08:09 thomasaw

I'm having this same issue on Xcode 7.2 . I'm on the latest objective c Branch. Is there a way to solve this, other then suppress the warning? thanks

mgil-xx avatar Jun 26 '16 16:06 mgil-xx

This warning appears since the designated initializer of the super class (NSObject > init) is not implemented in CHCSVParser and CHCSVWriter classes. The reason it's not implemented is that the library creator wished us the developers to use only the designated and convenience initializers defined in these classes.

In my own code I use the following approach in similar cases:

  1. In the h file, I am adding the following declaration:
  • (instancetype)init NS_UNAVAILABLE;
  1. In the m file, I am adding the following implementation:

  2. (instancetype)init {

    [NSException raise:NSInternalInconsistencyException format:@"Illegal call to designated initializer of super class (%@). Please call only initializers defined in this class!", NSStringFromSelector(_cmd)];

    return nil; }

This way, warnings are gone, calling to the init initializer will generate a compile time error, and getting somehow to the init initializer method bypassing the compiler error (maybe by dynamic dispatch) will generate a runtime exception.

Any thoughts?

yoasha avatar Jun 26 '16 18:06 yoasha

Hi yoasha, I tried your implementation without success. a new warning says "Convenience initializer missing a 'self' call to another initializer" thanks for helping

mgil-xx avatar Jun 27 '16 00:06 mgil-xx

It doesn't make a lot of sense... please try the following just to see what is wrong:

In the CHCSVParser.h remove the following code that I previously asked to add: - (instancetype)init NS_UNAVAILABLE; from the h file and add

In the CHCSVParser.m, replace the code that I previously suggested with the following one:

 - (instancetype)init {
    return [self initWithCSVString:nil];
}

Let me know if there are any warnings for the CHCSVParser class

yoasha avatar Jun 27 '16 07:06 yoasha

Hi yoasha, this solves one warning (@implementationCHCSVParser)`

using the same idea I added - (instancetype)init { return [self initForWritingToCSVFile:nil]; } to solve the second warning @implemantation CHCSVWriter this way, the warnings are gone.

I like your idea to add some alert to avoid the programmer trying to initialize using init. Maybe returning nil. Xcode asks to call self anyway, so I ended with this.

`-(instancetype)init {

self = [self initForWritingToCSVFile:nil];

[NSException raise:NSInternalInconsistencyException format:@"Illegal call to designated initializer of super class (%@). Please call only initializers defined in this class!", NSStringFromSelector(_cmd)];

return nil;

} ` thanks for helping

mgil-xx avatar Jun 28 '16 19:06 mgil-xx

Very interesting. In my code, I don't need to add the following line (just before the exception code) in order to prevent the warning: [self initForWritingToCSVFile:nil];

Having just the NSException code did the work for me. I am not sure why, but maybe it's related to the warning level preferences in Xcode which might be different in our dev environments.

BTW, after adding your code to the implementation file that prevented the warnings, did you try to add again the following line to the h file? - (instancetype)init NS_UNAVAILABLE;

This line should be very useful as it prevents calling this initializer at compile time rather than runtime.

yoasha avatar Jun 29 '16 06:06 yoasha

Hi yoasha,

good news! I didn't try before to just add - (instancetype)init NS_UNAVAILABLE; into the h file. The good news is that it solves the warnings and avoid the use of init .

I asked this same question on stackoverflow http://stackoverflow.com/questions/38044609/chcsvparser-warnings-how-to-solve-this-one, without answer. Would you like to answer this question with the help you give me? My english is really poor, and you guide me find the right solution. I really thank you for helping so much.

mgil-xx avatar Jun 30 '16 00:06 mgil-xx

Hi, I'm glad this helped.

@davedelong (or any user with admin rights), what do you think about this solution? I can submit a pull request if you find this solution legit.

yoasha avatar Jun 30 '16 06:06 yoasha