[swift-evolution] Allow ' in variable/constant names?

Charlie Monroe charlie at charliemonroe.net
Wed Jan 11 09:05:45 CST 2017


> On Jan 11, 2017, at 3:55 PM, Ben Rimmington <me at benrimmington.com> wrote:
> 
> 
>> On 11 Jan 2017, at 13:16, Charlie Monroe wrote:
>> 
>> Instead, I'd personally love better character support in Swift in the future and allow a Character literals using ' - just like in C, except with Unicode support:
>> 
>> let myChar = 'x' // Character
>> let myChar2 = '∃' // Character
>> let myChar3 = '\0' // NUL Character
>> let myChar4 = 'xyz' // Error from compiler
> 
> This feature was removed (just before the first Swift 1.0 beta). Search for "Single-quoted literals are no longer recognized" in the CHANGELOG.

I'm aware of that and think it's a shame. When you need a Character, you either need to declare the variable with type:

let c: Character = "a"

or use the initializer (which I prefer):

let c = Character("a")

--- but here, this is valid:

let c = Character("ax")

and will compile, yet crash at runtime.

I really hope that special syntax (single-quotes, or any other) is introduced back in the future.

> 
> <https://github.com/apple/swift/blob/master/CHANGELOG.md#2014-05-13>
> 
> I'm looking forward to the "String re-evaluation" part of Swift 4 stage 1. Hopefully, the Character type will also be improved.
> 
> -- Ben
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170111/32c1fa98/attachment.html>


More information about the swift-evolution mailing list