"The declaration of this function is not a prototype warning in Xcode 9

When using Xcode 9, there are some compiler warnings that This function declaration is not a prototype . He suggests adding void to the body of the method, which will allow it. The problem I ran into is that these warnings are also UIApplication for the system API, such as the UIApplication delegate methods:

 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler 

This can be solved by the following:

 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)(void))completionHandler 

Now I'm wondering if delegate methods will work in the long run, or whether Apple will add void to later beta versions of iOS 11. I'm curious because if I turn on the void body, Xcode will complain about the mismatch of the method selectors (which makes sense) . Has anyone experienced the same problem so far?

+101
ios objective-c xcode ios11 xcode9-beta
Jun 10 '17 at 12:07 on
source share
1 answer

Block declaration with an empty bracket:

 void (^)() 

has the same semantics as a function pointer with an empty bracket:

 void (*)() 

This does not mean that there are no arguments. This means that no arguments are specified, so it opens the way to errors, since you can call it in the following ways:

 void (^block)() = ... block(); block(10); block(@"myString"); 

When declaring blocks without parameters, always use:

 void (^)(void) 

Apple hasn't done it right everywhere, and they probably don't fix it for older APIs for compatibility reasons. You will need to keep this warning there until you move to the new API.

You can also disable this warning ( -Wstrict-prototypes ): enter image description here

or using #pragma (thanks @davidisdk ):

 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wstrict-prototypes" - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler { } #pragma clang diagnostic pop 

See LLVM discussion here or openradar bug.

Please note that there were no changes in the internal work of the API, all code will work. We will know that the API is not as good as it should be.

+225
Jun 10 '17 at 12:36 on
source share
— -



All Articles