Implemented the "init(_: )" initialiser in the Bool+Init extension.

This commit is contained in:
2023-04-15 02:12:02 +02:00
parent 03fc508157
commit 642c109740
3 changed files with 98 additions and 2 deletions
+37
View File
@@ -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"
}
}