<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KDBDallas &#187; Programming</title>
	<atom:link href="http://kdbdallas.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://kdbdallas.com</link>
	<description>Mac and iPhone Developer, Husband, Father, all in one</description>
	<lastBuildDate>Tue, 03 Aug 2010 14:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Mac/iPhone: Show Available Usable Disk Space</title>
		<link>http://kdbdallas.com/2008/12/27/maciphone-show-availble-useable-diskspace/</link>
		<comments>http://kdbdallas.com/2008/12/27/maciphone-show-availble-useable-diskspace/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 00:18:53 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://kdbdallas.com/?p=102</guid>
		<description><![CDATA[If you have an application that allows users to upload content to the app, you might want to show the user how much space is available for them to use. This is especially true on the iPhone where it is not as easy for the user to quickly check if they have enough room to [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an application that allows users to upload content to the app, you might want to show the user how much space is available for them to use.</p>
<p>This is especially true on the iPhone where it is not as easy for the user to quickly check if they have enough room to upload a given file.</p>
<p>You may also want to check if there is enough space before you start the upload, so you can inform them that the file wont fit.</p>
<p>That brings you to the task of figuring out how much free space there is, and more importantly how much free space is left that you as an unprivileged program can access.</p>
<p>The following code is based towards the iPhone, however all that would be needed to change it to be used on the Mac is the location you are checking for free space, and the setting of the label.</p>
<p><strong>NOTE:</strong> <em>The below &#8220;shown&#8221; code is old. The updated code is in the zip file at the bottom</em></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#include &lt;sys/param.h&gt;</span>
<span style="color: #6e371a;">#include &lt;sys/mount.h&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>sizeType;
&nbsp;
<span style="color: #a61390;">float</span> availableDisk;
&nbsp;
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>paths <span style="color: #002200;">=</span> NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #a61390;">struct</span> statfs tStats;
&nbsp;
statfs<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>paths lastObject<span style="color: #002200;">&#93;</span> cString<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>tStats<span style="color: #002200;">&#41;</span>;
&nbsp;
availableDisk <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>tStats.f_bavail <span style="color: #002200;">*</span> tStats.f_bsize<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>availableDisk &gt; <span style="color: #2400d9;">1024</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Kilobytes</span>
	availableDisk <span style="color: #002200;">=</span> availableDisk <span style="color: #002200;">/</span> <span style="color: #2400d9;">1024</span>;
&nbsp;
	sizeType <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot; KB&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>availableDisk &gt; <span style="color: #2400d9;">1024</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Megabytes</span>
	availableDisk <span style="color: #002200;">=</span> availableDisk <span style="color: #002200;">/</span> <span style="color: #2400d9;">1024</span>;
&nbsp;
	sizeType <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot; MB&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>availableDisk &gt; <span style="color: #2400d9;">1024</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Gigabytes</span>
	availableDisk <span style="color: #002200;">=</span> availableDisk <span style="color: #002200;">/</span> <span style="color: #2400d9;">1024</span>;
&nbsp;
	sizeType <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot; GB&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
diskSpaceLbl.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Available Disk Space: &quot;</span> stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%.2f&quot;</span>, availableDisk<span style="color: #002200;">&#93;</span> stringByAppendingString<span style="color: #002200;">:</span>sizeType<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This will give you something like the following:</p>
<p><img class="alignnone size-full wp-image-104" title="availablediskspace" src="http://kdbdallas.com/wp-content/uploads/2008/12/availablediskspace.png" alt="availablediskspace" width="257" height="29" /></p>
<p><strong><em>UPDATE:</em></strong><br />
I have gone a step further and made this into an easy to use class, that works out of the box with the iPhone and the Mac.</p>
<p><a href='http://www.kdbdallas.com/Code/FSStats.zip'><img src="http://kdbdallas.com/wp-includes/images/crystal/archive.png"/></a> <a href='http://www.kdbdallas.com/Code/FSStats.zip'>FSStats.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kdbdallas.com/2008/12/27/maciphone-show-availble-useable-diskspace/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Things Apple Left Out (toolchain)</title>
		<link>http://kdbdallas.com/2008/07/10/things-apple-left-out-toolchain/</link>
		<comments>http://kdbdallas.com/2008/07/10/things-apple-left-out-toolchain/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 09:28:35 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Toolchain]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://kdbdallas.com/?p=29</guid>
		<description><![CDATA[Lately there has been a lot of talk about the Apple iPhone SDK. Well some of us while working on the SDK are still also working on the Original SDK, AKA the Toolchain. Some might ask, &#8220;why if there is now the SDK would you still work on the toolchain?&#8221; Two reasons: Maintaining existing toolchain [...]]]></description>
			<content:encoded><![CDATA[<p>Lately there has been a lot of talk about the Apple iPhone SDK.</p>
<p>Well some of us while working on the SDK are still also working on the Original SDK, AKA the Toolchain.</p>
<p>Some might ask, &#8220;why if there is now the SDK would you still work on the toolchain?&#8221;</p>
<p>Two reasons:</p>
<ol>
<li>Maintaining existing toolchain applications</li>
<li>The SDK is VERY restrictive on what you can and can&#8217;t do, and if you break one of those rules then Apple won&#8217;t let you into the AppStore and you can not distribute your application.</li>
</ol>
<p>So I have been updating some of my applications recently and I keep running into the items that Apple forgot to add to the iPhone toolchain SDK.</p>
<p>For example XML processing was forgoten, as well as several parts of NSFileManager (like copying).</p>
<p>All of these I have had to fight with not having.</p>
<p>Well tonight I found a new one&#8230;</p>
<p>Seems Apple also forgot to include a LOT of the details contained in NSUserDefaults, not to mention that the few items that they did include are not set for the user root.</p>
<p>User root not having any defaults I can kind of understand, as with the later firmwares applications are not run as root anymore, but instead the user mobile.</p>
<p>While making some sense, it does not make total sense as some programs are still ran as root (such as daemons) (which just happens to be what I am dealing with).</p>
<p>So after jumping through the hoops of not having all the normal User Defaults while setting up the part of my application that runs as the user mobile to be able to have international/locale date support, I am now at a road block with getting the daemon part of my application which runs as root, to have the same support.</p>
<p>From what I can see even in the normal Cocoa SDK there is no way to get another users defaults (even if you have permission, ie: you are root). Maybe I am missing something as this is the first time I am dealing with international/localization programming.</p>
<p>If you happen to know how I can do this, please let me know&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://kdbdallas.com/2008/07/10/things-apple-left-out-toolchain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reached A New Development Milestone</title>
		<link>http://kdbdallas.com/2008/06/24/reached-a-new-development-milestone/</link>
		<comments>http://kdbdallas.com/2008/06/24/reached-a-new-development-milestone/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 06:32:39 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://kdbdallas.com/?p=23</guid>
		<description><![CDATA[I have reached a new milestone in my work as a programmer. What is that milestone you ask&#8230; My software is being cracked and distributed on the net by way of warez sites. This isn&#8217;t really a good thing, since all the people that steal it aren&#8217;t paying for it, and therefore taking money from [...]]]></description>
			<content:encoded><![CDATA[<p>I have reached a new milestone in my work as a programmer.</p>
<p>What is that milestone you ask&#8230;</p>
<p>My software is being cracked and distributed on the net by way of warez sites.</p>
<p>This isn&#8217;t really a good thing, since all the people that steal it aren&#8217;t paying for it, and therefore taking money from me, but at the same time it is kind of cool.</p>
<p>OK, that&#8217;s long enough&#8230; STOP STEALING MY STUFF!!!!</p>
<p> <img src='http://kdbdallas.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kdbdallas.com/2008/06/24/reached-a-new-development-milestone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
