Implemented the "init(_: )" initialiser in the Bool+Init extension.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Bool+Init.swift
|
||||
// Core
|
||||
//
|
||||
// Created by Javier Cicchelli on 15/04/2023.
|
||||
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
public extension Bool {
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
/// Initialise a boolean primitive out of a given string.
|
||||
/// - Parameter string: A string to initialise the boolean with.
|
||||
init(_ string: String) {
|
||||
let strings: [String] = [
|
||||
.Constants.oneNumber,
|
||||
.Constants.oneWord,
|
||||
.Constants.true,
|
||||
.Constants.yes
|
||||
]
|
||||
|
||||
self = strings.contains(string.lowercased())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum Constants {
|
||||
static let yes = "yes"
|
||||
static let `true` = "true"
|
||||
static let oneWord = "one"
|
||||
static let oneNumber = "1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user