<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Cocoa Tip: Extend NSNumber</title>
	<atom:link href="http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/</link>
	<description>fill the void</description>
	<lastBuildDate>Mon, 30 Jan 2012 09:42:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/comment-page-1/#comment-15513</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Sat, 22 Oct 2011 18:59:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/?p=464#comment-15513</guid>
		<description>@Giovanni Yep, you just need to convert the &lt;tt&gt;unsigned long long&lt;/tt&gt; file size into an &lt;tt&gt;NSNumber&lt;/tt&gt; before you pass it to &lt;tt&gt;[NSNumber humanReadableBase10&lt;/tt&gt;. Like so:

[sourcecode language=&quot;objc&quot;]
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfItemAtPath:[@&quot;~/Library/Safari/History.plist&quot; stringByStandardizingPath] error:NULL];
NSNumber *size = [NSNumber numberWithUnsignedLongLong:[attributes fileSize]];
NSLog(@&quot;%@&quot;, [size humanReadableBase10]);
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>@Giovanni Yep, you just need to convert the <tt>unsigned long long</tt> file size into an <tt>NSNumber</tt> before you pass it to <tt>[NSNumber humanReadableBase10</tt>. Like so:</p>
<pre class="brush: objc; title: ; notranslate">
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfItemAtPath:[@&quot;~/Library/Safari/History.plist&quot; stringByStandardizingPath] error:NULL];
NSNumber *size = [NSNumber numberWithUnsignedLongLong:[attributes fileSize]];
NSLog(@&quot;%@&quot;, [size humanReadableBase10]);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giovanni</title>
		<link>http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/comment-page-1/#comment-15479</link>
		<dc:creator>Giovanni</dc:creator>
		<pubDate>Sat, 22 Oct 2011 09:01:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/?p=464#comment-15479</guid>
		<description>If I want to use your code in base 10 with:

NSFileManager *fm3 = [NSFileManager defaultManager];
    NSLog(@&quot;%llu bites&quot;, [[fm3 attributesOfItemAtPath:[@&quot;~/Library/Safari/History.plist&quot; stringByStandardizingPath] error:NULL] fileSize]);

is possible?
Thanks!


- (NSString *)humanReadableBase10 {
    if (self == nil) return nil;
 
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    [formatter setMaximumFractionDigits:1];
 
    NSString *formattedString = nil;
    uint64_t size = [self unsignedLongLongValue];
    if (size &lt; 1000) {
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size]];
        formattedString = [NSString stringWithFormat:@&quot;%@ B&quot;, formattedNumber];
    }
    else if (size &lt; 1000 * 1000) {
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0]];
        formattedString = [NSString stringWithFormat:@&quot;%@ KB&quot;, formattedNumber];
    }
    else if (size &lt; 1000 * 1000 * 1000) {
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0 / 1000.0]];
        formattedString = [NSString stringWithFormat:@&quot;%@ MB&quot;, formattedNumber];
    }
    else {
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0 / 1000.0 / 1000.0]];
        formattedString = [NSString stringWithFormat:@&quot;%@ GB&quot;, formattedNumber];
    }
    [formatter release];
 
    return formattedString;
}</description>
		<content:encoded><![CDATA[<p>If I want to use your code in base 10 with:</p>
<p>NSFileManager *fm3 = [NSFileManager defaultManager];<br />
    NSLog(@&#8221;%llu bites&#8221;, [[fm3 attributesOfItemAtPath:[@"~/Library/Safari/History.plist" stringByStandardizingPath] error:NULL] fileSize]);</p>
<p>is possible?<br />
Thanks!</p>
<p>- (NSString *)humanReadableBase10 {<br />
    if (self == nil) return nil;</p>
<p>    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];<br />
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];<br />
    [formatter setMaximumFractionDigits:1];</p>
<p>    NSString *formattedString = nil;<br />
    uint64_t size = [self unsignedLongLongValue];<br />
    if (size &lt; 1000) {<br />
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size]];<br />
        formattedString = [NSString stringWithFormat:@&quot;%@ B&quot;, formattedNumber];<br />
    }<br />
    else if (size &lt; 1000 * 1000) {<br />
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0]];<br />
        formattedString = [NSString stringWithFormat:@&quot;%@ KB&quot;, formattedNumber];<br />
    }<br />
    else if (size &lt; 1000 * 1000 * 1000) {<br />
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0 / 1000.0]];<br />
        formattedString = [NSString stringWithFormat:@&quot;%@ MB&quot;, formattedNumber];<br />
    }<br />
    else {<br />
        NSString *formattedNumber = [formatter stringFromNumber:[NSNumber numberWithFloat:size / 1000.0 / 1000.0 / 1000.0]];<br />
        formattedString = [NSString stringWithFormat:@&quot;%@ GB&quot;, formattedNumber];<br />
    }<br />
    [formatter release];</p>
<p>    return formattedString;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/comment-page-1/#comment-3059</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Mon, 14 Dec 2009 04:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/?p=464#comment-3059</guid>
		<description>Excellent point! I&#039;d forgotten about that change. I updated the code to reflect that. Thanks!</description>
		<content:encoded><![CDATA[<p>Excellent point! I&#8217;d forgotten about that change. I updated the code to reflect that. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://www.bdunagan.com/2009/11/24/cocoa-tip-extend-nsnumber/comment-page-1/#comment-2988</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Tue, 08 Dec 2009 18:17:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/?p=464#comment-2988</guid>
		<description>You should probably be dividing by 1000 not 1024. :)  mega = 1000, mebi = 1024.  See http://en.wikipedia.org/wiki/Binary_prefixes#IEC_standard_prefixes  As of 10.6 Apple reports memory sizes consistently in base 2 and other sizes (file, disk, etc.) in base 10.  Though they annoyingly use the base 10 prefix in all instances.</description>
		<content:encoded><![CDATA[<p>You should probably be dividing by 1000 not 1024. <img src='http://www.bdunagan.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   mega = 1000, mebi = 1024.  See <a href="http://en.wikipedia.org/wiki/Binary_prefixes#IEC_standard_prefixes" rel="nofollow">http://en.wikipedia.org/wiki/Binary_prefixes#IEC_standard_prefixes</a>  As of 10.6 Apple reports memory sizes consistently in base 2 and other sizes (file, disk, etc.) in base 10.  Though they annoyingly use the base 10 prefix in all instances.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

