开发者

Can't get rid of this warning?

I'm getting this warning "Format not a string literal and no format arguments? Any ideas?

-(BOOL)isFirstPointReached{

    NSStri开发者_运维技巧ng *firstPoint = [NSString stringWithFormat:[pointsToFillArray objectAtIndex:0]];
    NSString *lastPoint = [NSString stringWithFormat:[pointsToFillArray lastObject]];

    if([firstPoint isEqualToString:lastPoint]){

        return YES;
    }

    else{ 

        return NO;
    }
}


A few points...

The pointsToFillArray is an array of objects and the compiler does not know if it contains NSStrings or any other type of object. To get rid of the error you would cast it to (NSString*)

Secondly, the stringWithFormat is normally used to create a string from a few different pieces of data and does not need to be used in this case

Thirdly, you could just create pointers to the objects within the array and then do your check

The following should work for you:

NSString *firstPoint = (NSString*)[pointsToFillArray objectAtIndex:0];
NSString *lastPoint = (NSString*)[pointsToFillArray lastObject];

if ([firstPoint isEqualToString:lastPoint]) {
   return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜