0

このコードが完全に機能する理由を誰かが説明できますか?

int thumbnailPrefix = trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]);

newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",thumbnailPrefix,@"png"];

しかし、このコードは不正アクセスエラーを引き起こしますか?

newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]),@"png"];
4

2 に答える 2

2

truncdoubleではなく、を返しますint

double trunc(double x);

したがって、最初のコードブロックでは、それをに変換し、フォーマット指定子intを正しく使用しています。%d

第二に、それは、%fであるか、その(int)前にある必要があります。

newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",(int)trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]),@"png"];
于 2011-08-22T16:26:22.090 に答える
0

trunk()からの戻り値を次のように型キャストしてみましたか?

newGraph.thumbnailImageName = [NSString stringWithFormat:@"%d.%@",(int)trunc([newGraph.dateCreated timeIntervalSinceReferenceDate]),@"png"];

暗闇の中でのショットですが、NSStringは関数truncの戻り型を認識していないと思います。

于 2011-08-22T16:26:28.630 に答える