Search code examples
objective-cnslog

iOS: Warning message "Format specifies type 'int' but the argument has type 'char *(*)(const char *, int)'"


I have an error message on the 2nd NSLog for the %c:

for info, here is the type of 'index' char => *index(const char *, int) __POSIX_C_DEPRECATED(200112L);

I don't understand what type I have to put here:

@try {
     [[cellToFill valueForKey:@"_textField"] setAutocapitalizationType: [[color valueForKey:@"textField.autocapitalizationType"] integerValue]];
}
@catch (NSException *exception) {
    NSLog(@"%@", exception.reason);
}
@finally {
    NSLog(@"Char at index %c cannot be found", index); 
}

What is the good type to put in the NSLog to avoid that warning?


Solution

  • You have probably written the wrong identifier, index, in your NSLog() call.

    You code suggests you believe index is a character variable (e.g. declared as char index;) somewhere.

    The error message states that index is of type char *(*)(const char *, int), that is: a pointer to a function which takes a character pointer and an integer value and returns a character pointer.

    Now it just happens there is a standard C library function index() of exactly that type.

    Conclusion: you have mistyped your variable name as index, or typed it where it is out of scape, and therefore are getting the C library function – if you just write a function name in (Objective-)C you get a value which is a pointer to the function, exactly as your error message describes.