Swift Tutorial: Introduction 09 - Variables: Characters

Written by Paul Napier on . Posted in Swift Tutorials: Introduction

Hello everyone and welcome to the ninth tutorial in programming with swift brought to you by MadApper. My name is Paul Napier and in this session we will be covering characters.

Characters in programming are another of the basic types. They are a unit of information which have a graphical representation such as a letter, number or punctuation. In Swift you can create a character variable by declaring the type as a Character, then setting the value inside a set of parentheses. i.e.

var char:Character = "a"

Notice, however, that when declaring a character, the value cannot be longer than a single letter. 

Another set of characters for you to be aware of are string literals. There are several ones you will come across regularly:

\0 (null character),

\\ (backslash),

\t (horizontal tab),

\n (line feed),

\r (carriage return),

\" (double quote) and

\' (single quote).

You are also able to create string literal characters by declaring their Unicode values. Unicode is an encoding format that is used to represent characters across the world's computers. In order to do this, you can follow the same process as before, but instead of writing the character, you can write a \x followed by a 2 digit hexadecimal number or a \U followed by either a 4 or an 8 digit hexadecimal number representing the character you want.

Although you may not require this technique often, it is still useful to understand that this is how the computer recognises characters and that the capital and lowercase versions of a letter are actually seen as different by the device. So for example the letter A would be \U00000041 where as the lowercase version would be \U00000061.

Another instance where this is useful is for non standard characters, such as glyphs. So a star will be \U00002605 and a hammer and sickle is \U0000262D. Or you may wish to represent alternative alphabets and writing systems such as Arabic, Cyrillic or Chinese.

If you need further examples of characters and their Unicode values there are lots of useful resources on the web. However, one of the best tools is

Ok! That's covered off the basics of characters. In the next session we are going to build upon this concept and start talking about strings. 


0 #147 Abbie 2017-12-07 09:20
Sweet blog! I found it while surfing around on Yahoo
News. Do yoou hve any suggestions on how too get
listed inn Yahoo News? I've been trying for a
while bbut I never seem to get there! Many thanks
0 #146 Shannan 2017-12-07 06:54
The front facing camera remains identical as the Mi6.

my web-site; Shannan:
0 #145 FirstPenelope 2017-10-29 11:03
I have noticed you don't monetize your blog, don't waste your traffic, you can earn additional cash
every month because you've got high quality content.
If you want to know how to make extra $$$, search for: Mrdalekjd methods for $$$
0 #144 ecu Ignition Coil 2017-09-25 19:19
Does your site have a contact page? I'm having a tough time locating it but, I'd like tto send you an e-mail.
I've got some creative ideas for youur bloog you
might bbe interested in hearing. Either way, great site and I look forward to seeing it grow over time.
0 #143 Kids Leather Gear 2017-08-10 18:39
This post is worth everyone's attention. When can I find out more?

my website :: Kids Leather
0 #142 Leather Clothing 2017-08-07 21:54
Wow, amazing blog structure! How lengthy have you been blogging for?
you made running a blog look easy. The whole glance of your site is fantastic, as well as the content!

my web blog - Leather Clothing:
0 #141 Skinny Jeans 2017-07-25 06:00
We absolutely love your blog and find almost all
of your post's to be just what I'm looking for.
can you offer guest writers to write content for you personally?
I wouldn't mind publishing a post or elaborating on some of the subjects you write about here.
Again, awesome blog!

My homepage: Skinny Jeans:
0 #140 gay Leather 2017-07-13 22:08
I'm not sure why but this site is loading extremely slow for me.
Is anyone else having this issue or is it a problem on my end?
I'll check back later on and see if the problem still exists.

Also visit my page :: gay Leather:
0 #139 rom 2017-07-09 01:22
eⲭcellent submit, very infoгmative. I ponder why the other experts of
this sectоr don't noticе this. You must proceed your ѡriting.

I am sure, you haᴠe a һuge readers' base already!

My blog post rom:
0 #138 shop 2017-07-07 17:22
I don't even know how I ended up here, but I thought this post was good.
I don't know who you are but certainly you are going to a famous blogger
if you are not already ;) Cheers!

Also visit my webpage: shop:

Add comment

Security code