Skip to content

Instantly share code, notes, and snippets.

@kusakusakusa
Last active August 29, 2015 14:20
Show Gist options
  • Save kusakusakusa/d202da9978464d63a6c3 to your computer and use it in GitHub Desktop.
Save kusakusakusa/d202da9978464d63a6c3 to your computer and use it in GitHub Desktop.
iOS
func deviceRemainingFreeSpaceInBytes() -> Int64? {
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let systemAttributes = NSFileManager.defaultManager().attributesOfFileSystemForPath(documentDirectoryPath.last as String, error: nil)
let freeSize = (systemAttributes?[NSFileSystemFreeSize] as? NSNumber)?.longLongValue
return freeSize
}
if let bytes = deviceRemainingFreeSpaceInBytes() {
println("free space: \(bytes)")
} else {
println("failed")
}
func displayErrorAlert (title :String, error :String) {
var alert = UIAlertController(title: title, message: error, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
var activityIndicator = UIActivityIndicatorView()
func loadSpinner() {
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}
var refresher: UIRefreshControl!
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
func refresh() {
// code to execute during refresh
refresher.endRefreshing()
}
var activityIndicator = UIActivityIndicatorView()
func unloadSpinner() {
activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment