As per apple documentation, Swift types can be classified into two, namely,

Each of these types are explained below in detail.

Named types

Named types, as the name implies are types with variable names. The named types can be both Swift standard library types and user defined types. It includes the following,

We will be covering primitive types and optional types in this page and the rest in their respective pages to which they are linked.

Primitive Types

In all programming languages, we have some basic types that available part of the language. In swift, we have these types availed through the Swift standard library. These include the types for numbers, characters and strings. The following table covers all the primitive types.

6UInt
Represents an unsigned integer. Internally Int refers to UInt32 in 32 bit platform and UInt64 in 64 bit platform.12Double
Represents 64 bit floating point number.

Primitive Types
SNo. Type and use
1 Int
Represents an integer. Internally Int refers to Int32 in 32 bit platform and Int64 in 64 bit platform.
2 Int64
Represents 64 bit integer.
3 Int32
Represents 32 bit integer.
4 Int16
Represents to 16 bit integer.
5 Int8
Represents to 8 bit integer.
7 UInt64
Represents 64 bit unsigned integer.
8 UInt32
Represents 32 bit unsigned integer.
9 UInt16
Represents 16 bit unsigned integer.
10 UInt8
Represents 8 bit unsigned integer.
11 Float
Represents 32 bit floating point number.
13 Bool
Represents a boolean and has two states true and false.
14 Character
Represents a single character. It accepts unicode characters.
15 String
Represents strings which is actually a collection of type Character.

Some examples are given below for the above types.

var myInteger:Int = -100
println("myInteger: \(myInteger)")

var myUnsigedInteger:UInt = 100
println("myUnsigedInteger: \(myUnsigedInteger)")

var myFloat:Float = 98.95
println("myFloat: \(myFloat)")

var myDouble:Double = 88.85
println("myDouble: \(myDouble)")

var myBoolean:Bool = true;
println("myBoolean: \(myBoolean)")

var testChar:Character = "T";
println("testChar: \(testChar)")

var testString:String = "Eezy Tutorials";
println("testString: \(testString)")

When we run the above program, we will get the following output.

myInteger: -100
myUnsigedInteger: 100
myFloat: 98.9499969482422
myDouble: 88.85
myBoolean: true
testChar: T
testString: Eezy Tutorials

Note on Primitive datatypes

Quick Facts !!!

Primitive datatypes in Swift are created using structures and hence you cannot convert C types to Swift primitive types. Instead, you can use some equivalent types.

Optional Type

The primitive types are formed with the help of structures. The variables that refer to these primitive types can either contain value or no value. In order to set no value state, we should use the optional type. Optional type is formed by adding a question mark(?) to the primitive type. This optional type accepts nil for no value state. Example for optional type is given below.

var myOptionalInteger:Int?
println("myOptionalInteger: \(myOptionalInteger)")

myOptionalInteger = 10;
println("myOptionalInteger: \(myOptionalInteger)")

var myOptionalFloat:Float?
println("myOptionalFloat: \(myOptionalFloat)")

myOptionalFloat = 10.536;
println("myOptionalFloat: \(myOptionalFloat)")

var myOptionalString:String?
println("myOptionalString: \(myOptionalString)")

myOptionalString = "Eezy Tutorials";
println("myOptionalString: \(myOptionalString)")

When we run the above program, we will get the following output.

myOptionalInteger: nil
myOptionalInteger: 10
myOptionalFloat: nil
myOptionalFloat: 10.53600025177
myOptionalString: nil
myOptionalString: Eezy Tutorials

Quick Note to Objective C developers

Remember !!!

The nil used in Objective-C is not equivalent to the nil used in Swift. nil is a pointer to non existing object in Objective-C and in Swift used for non existent value including primitive types with the help of optionals.

Compound types

Compound types is type without name that can contain named and compound types. It includes,

Use the respective links to know more with relevant examples.