Skip to content

Instantly share code, notes, and snippets.

@pedantix
Created March 27, 2016 02:11
Show Gist options
  • Save pedantix/9ed41e23d1bcc29ab9bf to your computer and use it in GitHub Desktop.
Save pedantix/9ed41e23d1bcc29ab9bf to your computer and use it in GitHub Desktop.
How to add ruby-ish property accessors to String in swift that I find myself using a lot
extension String {
var blank: Bool {
get {
let trimmed = self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
return trimmed.isEmpty
}
}
var present: Bool {
get{
return !blank
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment