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
···
-----Original Message-----
From: "Arsen Gasparyan via swift-evolution" <swift-evolution@swift.org>
Sent: 04/06/2016 10:10 AM
To: "swift-evolution@swift.org" <swift-evolution@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.
Since the XML and JSON related objects are part of Foundation, I think it would be great to have that functionality in Foundation as well. For “true”, “false”, “1” and “0” (in addition to 1 and 0).
Mirek
···
On Jun 4, 2016, at 06:10, Arsen Gasparyan via swift-evolution <swift-evolution@swift.org> wrote:
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.
I'm not particularly in favor of a String initializer for booleans. In fact, I'm not particularly in favor of a String initializer for any numeric type.
(I understand that English keyboards don't have acute accents and that people write it Felix. However, it is less understandable when a machine processes my name and I wrote it right in the first place.)
Providing numeric type initializers that accept a String and interpret it with the C locale is a step backwards in the direction of supporting non-English languages. Even if you put a big red flag around the method and say "this uses the C locale and is improper for international inputs", the fact is that the C locale is essentially the American locale, and it's been proven over and over that humans will use the wrong tool if it is simpler than the right tool.
There is value in reading interchange formats like JSON. However, these languages define their own grammar and syntax. I see little benefit in letting that grammar and syntax leak into the realm of parsing values in the general case.
Félix
···
Le 4 juin 2016 à 11:38:04, Mirek Elsner via swift-evolution <swift-evolution@swift.org> a écrit :
Since the XML and JSON related objects are part of Foundation, I think it would be great to have that functionality in Foundation as well. For “true”, “false”, “1” and “0” (in addition to 1 and 0).
Mirek
On Jun 4, 2016, at 06:10, Arsen Gasparyan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
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.
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.
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@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@swift.org>
Sent: 04/06/2016 10:10 AM
To: swift-evolution@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.
IMO, that is too idiosyncratic to be a standard language feature. You should extend Bool based on the specific needs of your application. Thats what the extensions are for.
Best,
t.
···
On 04 Jun 2016, at 15:10, Arsen Gasparyan via swift-evolution <swift-evolution@swift.org> wrote:
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.
You may be right, but I'd imagine such a conversion function would be in pretty much any library for serializing/deserializing data.
I can't recall if this has been discussed before, but are we committed to One Standard Library to Rule Them All, or might we consider having a "standard" library and a "common extensions" library? (Personally, I'd prefer them to be split up so that 3rd-party library authors can import only what they need, but maybe that's just me.)
- Dave Sweeris
···
On Jun 4, 2016, at 08:26, Taras Zakharko via swift-evolution <swift-evolution@swift.org> wrote:
IMO, that is too idiosyncratic to be a standard language feature. You should extend Bool based on the specific needs of your application. Thats what the extensions are for.
Best,
t.
On 04 Jun 2016, at 15:10, Arsen Gasparyan via swift-evolution <swift-evolution@swift.org> wrote:
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.