NEW: Foundational Tools in Android On-Demand Bootcamp!
Dive into Android development essentials with our latest beginner program. Learn at your pace with
personalized support. From installation to Jetpack Compose, gain the skills you need for success!
Previous episode: 02. Supercharge User Defaults
Next episode: 04. Log Property Access
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
struct WhitespaceValidation: Validation {
struct Options: OptionSet {
let rawValue: Int
static let trailing = Options(rawValue: 1 << 0)
static let leading = Options(rawValue: 1 << 1)
static let all: Options = [.leading, .trailing]
}
typealias Value = String
let options: Options
func validate(_ value: String) -> Bool {
return !value.isEmpty
}
func sanitize(_ value: String) -> String {
var value = value
if self.options.contains(.leading) {
while value.first?.isWhitespace == true {
value.removeFirst()
}
}
if self.options.contains(.trailing) {
while value.last?.isWhitespace == true {
value.removeLast()
}
}
return value
}
static let trailing = WhitespaceValidation(options: .leading)
static let leading = WhitespaceValidation(options: .trailing)
static let all = WhitespaceValidation(options: .all)
}```
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.