[swift-evolution] Add conversion String -> Bool

Arsen Gasparyan to.arsen.gasparyan at gmail.com
Sat Jun 4 08:23:16 CDT 2016


Agree about "1" and "0" because it's a valid XML boolean value. But I don't
know where you can find "yes" / "no" value.

http://www.w3schools.com/xml/schema_dtypes_misc.asp
Note: Legal values for boolean are true, false, 1 (which indicates true),
and 0 (which indicates false).

On Sat, Jun 4, 2016 at 4:14 PM Leonardo Pessoa <me at lmpessoa.com> wrote:

> I think it would be interesting if it could also recognise "1" and "yes"
> too as it can be useful in some cases. Perhaps have an option for this
> converter to be customised.
>
> L
> ------------------------------
> From: Arsen Gasparyan via swift-evolution <swift-evolution at swift.org>
> Sent: ‎04/‎06/‎2016 10:10 AM
> To: swift-evolution at swift.org
> Subject: [swift-evolution] Add conversion String -> Bool
>
> Hello,
>
> It would be great if we had `init?(_ text: String)` for Bool class.
> Because sometime when you're processing JSON/XML it can help you a lot.
>
> Examples:
>
> Bool("true") -> true
> Bool("false") -> false
> Bool("TrUE") -> true
> Bool(" true ") -> nil
> Bool("1") -> nil
> Bool("Y") -> nil
> Bool("whatever") -> nil
>
>
>
> via https://bugs.swift.org/browse/SR-1282
>
> Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160604/8ea00ed1/attachment.html>


More information about the swift-evolution mailing list