1
NSFileSystemFreeSizeの結果を利用可能なmb/gbのユーザフレンドリな文字列に変換するルーチンを持っている人はいませんか?私はそれの要点を持っていると思ったが、私は奇妙な結果を得ている。甘いNSFileSystemFreeSize:結果をmb/gbのユーザーフレンドリーな表示に変換しますか?
- (NSString*)getFreeSpace
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:documentsDirectory error:NULL];
unsigned long long freeSpaceInBytes = [[fileAttributes objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSString * space = [NSString stringWithFormat:@"Free Space: %fll", freeSpaceInBytes /1024./1024. /1024.];
NSLog(@"freeSpaceInBytes %llull %fll", freeSpaceInBytes, freeSpaceInBytes /1024./1024. /1024.);
return space;
}
!ありがとうございました。私は決してエレガントなものを思いついたことはありません。 –
ねえ、私はobjective-cに新しいです。私はこのNSStringをどのように記録できるのでしょうか? NSLog(@ "%@"、prettyBytes);は動作していません 'Formatは 'id'型を指定しますが、引数は 'NSString *(*)(uint64_t)' '型です。 – iDev
あなたはそれ自身に関数を送信しています。あなたは何かでそれを呼び出す必要があります... NSLog(@ "%@"、prettyBytes(someNumberOfBytes)) ' –