Can anyone explain why this code works perfectly:
int thumbnailPrefix = trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]);
newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",thumbnailPrefix,@"png"];
But this code causes a Bad Access error?
newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]),@"png"];
truncreturns adouble, not anint.So in the first code block you are converting it to an
int, and correctly using the%dformat specifier.In the second, it should be an
%f, or have(int)in front of it.