Home iOS Development ios – Is there official reasoning as to why Swift does not use single quotes for strings? And if there is, what is it?

ios – Is there official reasoning as to why Swift does not use single quotes for strings? And if there is, what is it?

0

[ad_1]

I’m just learning Swift and one issue that keeps bugging me is that I can’t use single quotes to denote strings. Many programming languages let you use single quote or double quote to denote a string, but Swift restricts this.

I attempted to Google this but only get results about Strings and one StackOverflow answer that says “There’s no such thing as a single quote in Swift.”

The Lexical Structure page and the Strings and Characters page in the Swift Language reference also just talk about string literals as made of double quotation marks. They make no mention of why single quotes are not allowed.

Furthermore, both of those pages reference using a single quote in a string if you escape it first (\'). This seems odd. Usually you have to escape a quote in a language if it matches the quote that strings are made from, so you have to escape a double quote in a double quote string (" \" ") or a single quote in single quote string (' \' '). But to escape a single quote in a double quote string seems unnecessary (" ' "). So why mention escaping it unless single quoted strings are somehow an option?

So, as per the title:

  1. Is there official reasoning as to why Swift does not use single quotes for strings?
  2. And if there is, what is it?

Note on why it matters:

  • It is more efficient to hit a singular key to type a single quote than it is to hit two keys to type a double quote.

  • Many languages let you make strings with both, so why is Swift being annoyingly restrictive?

[ad_2]