-2
-(void)updateResult {
    @try {
        if (questionFlag == INSERT_IMAGE_DETAILS) {
            [self getImageDetail];
            [m_ivwMainConsumerImage setImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:PROFILE_PHOTO_FILEPATH,[[[DataModel sharedConsumerData] images] lastObject]]]];
        }
    }
    @catch ....

I am new to Objective C and the above code snippet is a part of a program where I am getting the warning: 'More % conversions than data argument' for the line

[m_ivwMainConsumerImage setImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:PROFILE_PHOTO_FILEPATH,[[[DataModel sharedConsumerData] images] lastObject]]]];

Can you please let me know how to overcome this error?

Thanks

devops_engineer
  • 599
  • 1
  • 5
  • 13
  • 1
    What is `PROFILE_PHOTO_FILEPATH`? – Larme Jun 30 '15 at 12:00
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. – Hot Licks Jun 30 '15 at 12:10

1 Answers1

2

This error means that your formatting string (PROFILE_PHOTO_FILEPATH) has more format specifiers than parameters you are providing to it (you are only providing one, the lastObject of the DataModel's images).

For example:

if PROFILE_PHOTO_FILEPATH is "%@ %d" it expects some object %@ and an integer %d. So you would need to call stringWithFormat: this way:

[NSString stringWithFormat:PROFILE_PHOTO_FILEPATH, [[[DataModel sharedConsumerData] images] lastObject], 42];

Obviously this is just an example, without seeing the contents of PROFILE_PHOTO_FILEPATH I can't be more specific.

See this document for more details on how string format specifiers work:

https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

Steve Wilford
  • 8,894
  • 5
  • 42
  • 66