swift - emoji cannot be a literal and what else? -


a literal source code representation of value of type, such number or string

there 3 kinds of literals in swift: integer literals, floating-point literals , string literals (please correct me if i'm wrong), means (my guess) elements not belong type of integer, floating or string not considered literal, , trigger error when used literals

according guess i've tried let aemoji = 😀

enter image description here

question1: guess accurate? if not, appreciate correct me.

question2: there else shouldn't use literal? (would nice give me example)

thanks

  1. yes, isn't integer literal (1), floating-point literal (1.0) or string literal ("foo"), array literal ([foo]), dictionary literal ([foo : bar]), bool literal (true/false) isn't literal , cause error.

  2. anything isn't 1 of literals above isn't literal, , cause error (if it's invalid syntax).

you can make put emoji in string literal, however: let aemoji = "😀"


Comments