Skip to content

Instantly share code, notes, and snippets.

@B0bcat
Last active September 16, 2015 04:04
Show Gist options
  • Save B0bcat/4bbecf8bf32faeb98011 to your computer and use it in GitHub Desktop.
Save B0bcat/4bbecf8bf32faeb98011 to your computer and use it in GitHub Desktop.
Schwifty
class FileWriter {
func writeDocument(text: String?, completion((Bool, NSError?) -> Void)?) -> NSError? {
var error: NSError?
if let cText = text {
dispatch_async(myQueue) {() -> Void in
let error = writeAndSaveFile(cText)
completion?((error == nil), error)
}
} else {
error = NSError.dataEmptyError()
}
return error
}
}
class Foo {
func userDidTypeText(text: String?) {
if let error = FileWriter().writeDocument(text) {(success, writeError) in
// Stop loading indicator
// Show alert with writeError
} {
// Show alert with error
} else {
// Start loading indicator
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment