title: Query Available iOS Disk Space with Swift
body: <p>I'm trying to get the available iOS device storage using <code>Swift</code>.  I found this function <a href="https://stackoverflow.com/a/25142432/633251">here</a></p>
  
  <pre><code>        func deviceRemainingFreeSpaceInBytes() -&gt; NSNumber {
            let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
            let systemAttributes = NSFileManager.defaultManager().attributesOfFileSystemForPath(documentDirectoryPath.last as String, error: nil)
            return systemAttributes[NSFileSystemFreeSize] as NSNumber
          }
  </code></pre>
  
  <p>But at compile time this error is given: <code>[NSObject : AnyObject]? does not have a member named 'subscript'</code>  I believe this error arises from the issue mentioned <a href="https://stackoverflow.com/a/25451390/633251">here</a>, namely that <code>attributesOfFileSystemForPath</code> returns an optional dictionary (<a href="https://developer.apple.com/Library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html#//apple_ref/occ/instm/NSFileManager/attributesOfFileSystemForPath:error:" rel="noreferrer">documentation</a>).  I understand the problem in a general sense, but because the suggested solution involves a nested case, I don't quite see how to fix the function I'm interested in (it doesn't help that I'm quite new to <code>Swift</code>).  Can someone suggest how to make the function work?  NOTE: I'm not sure if the original function was tested by the author or if it worked under an xcode 6 beta, but it doesn't work under the GM as far as I can see.</p>