Last active
August 29, 2015 14:20
-
-
Save kusakusakusa/d202da9978464d63a6c3 to your computer and use it in GitHub Desktop.
iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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