Created
March 27, 2016 02:11
-
-
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
This file contains 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
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