Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two warnings when building using XCode 7 Beta 5 #87

Open
yoasha opened this issue Aug 23, 2015 · 16 comments
Open

Two warnings when building using XCode 7 Beta 5 #87

yoasha opened this issue Aug 23, 2015 · 16 comments

Comments

@yoasha
Copy link

yoasha commented Aug 23, 2015

  • '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!

@JaxMyers
Copy link

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

@yoasha
Copy link
Author

yoasha commented Sep 14, 2015

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.

@thomasaw
Copy link

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

@jeffdgr8
Copy link

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.

@thomasaw
Copy link

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

@bakwarte
Copy link

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

@JaxMyers
Copy link

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

@thomasaw
Copy link

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.

@mgil-xx
Copy link

mgil-xx commented Jun 26, 2016

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

@yoasha
Copy link
Author

yoasha commented Jun 26, 2016

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?

@mgil-xx
Copy link

mgil-xx commented Jun 27, 2016

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

@yoasha
Copy link
Author

yoasha commented Jun 27, 2016

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

@mgil-xx
Copy link

mgil-xx commented Jun 28, 2016

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

@yoasha
Copy link
Author

yoasha commented Jun 29, 2016

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.

@mgil-xx
Copy link

mgil-xx commented Jun 30, 2016

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.

@yoasha
Copy link
Author

yoasha commented Jun 30, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants