Why there's no Character literals?


(Wang LiMing) #1

In Swift, we must specify the type for Character variables(because there’s no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type infer?


(Saagar Jha) #2

Well, what if you wanted to create a String with one character? There’s no
way to differentiate.

···

On Jul 7, 2016, at 02:35, 王 黎明 via swift-users [swift-users@swift.org](mailto:swift-users@swift.org) wrote: >

In Swift, we must specify the type for Character variables(because there’s
no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type
infer?
------------------------------

swift-users mailing list swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha


(Zhao Xin) #3

Of course not. Struct Set is commonly known.

let foo:Set = [1,2,3,4]

let bar:Set<Int> = [1,2,3,4]

If you do not specify them as Sets, foo and bar will be Arrays.

Zhaoxin

···

On Thu, Jul 7, 2016 at 5:35 PM, 王 黎明 <swift-users@swift.org> wrote:

In Swift, we must specify the type for Character variables(because there’s
no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type
infer?

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Rick M) #4

Well, what if you wanted to create a String with one character? There’s no way to differentiate.

That hardly seems like the justification. In that case, you'd specify the type:

    let s: String = '\n'

···

On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users <swift-users@swift.org> wrote:

> On Jul 7, 2016, at 02:35, 王 黎明 via swift-users [swift-users@swift.org](mailto:swift-users@swift.org) wrote: >

In Swift, we must specify the type for Character variables(because there’s no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type infer?

swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Rick Mann
rmann@latencyzero.com


(Saagar Jha) #5

Yes, but then a similar complaint could be made that I wanted a String this time. The only real way to tell the difference is to use something like single quotes.

···

On Jul 10, 2016, at 14:03, Rick Mann via swift-users <swift-users@swift.org> wrote:

On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users <swift-users@swift.org> wrote:

Well, what if you wanted to create a String with one character? There’s no way to differentiate.

That hardly seems like the justification. In that case, you'd specify the type:

   let s: String = '\n'

On Jul 7, 2016, at 02:35, 王 黎明 via swift-users [swift-users@swift.org](mailto:swift-users@swift.org) wrote: >

In Swift, we must specify the type for Character variables(because there’s no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type infer?

swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Rick Mann
rmann@latencyzero.com

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(James Campbell) #6

In Ruby they have special literals, like so:

So this would be an array of chars
%c{a b c d e f g}

···

*___________________________________*

*James⎥Head of Trolls*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 11 July 2016 at 05:56, Saagar Jha via swift-users <swift-users@swift.org> wrote:

Yes, but then a similar complaint could be made that I *wanted* a String
this time. The only real way to tell the difference is to use something
like single quotes.

On Jul 10, 2016, at 14:03, Rick Mann via swift-users < > swift-users@swift.org> wrote:

On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users < > swift-users@swift.org> wrote:

Well, what if you wanted to create a String with one character? There’s no
way to differentiate.

That hardly seems like the justification. In that case, you'd specify the
type:

   let s: String = '\n'

On Jul 7, 2016, at 02:35, 王 黎明 via swift-users [swift-users@swift.org]( > mailto:swift-users@swift.org <swift-users@swift.org>) wrote: >

In Swift, we must specify the type for Character variables(because there’s
no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type
infer?

swift-users mailing list swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Rick Mann
rmann@latencyzero.com

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users