In computer programming, data types represent the type of data of which can be stored into a variable.
SWIFT DATA TYPES
| Data | type | Example Description |
|---|---|---|
| Character | "a" | a 16-bit unicode scalar |
| String | "hello, world" | A Sequence of Character types |
| Int | 5 | Integer number |
| Float | 3.14 | 32-bit floating point number |
| Double | 2.345673954343 | 64-bit floating point number |
| Bool | true | Any of two values, true or false, or 1 and 0 |
Character represents a value made of one or more unicode scalar values, grouped by Unicode algorithm.
String is a unicode value that consists of the collection of Character values. Strings are unicode correct and are locale-insensitive, for efficiency.
Int is a signed integer value, on the 32-bit platforms, it is the same as Int32, and on 64-bit platform, it is the same as Int64. Range of an integer varies from: -231 to 231-1 (32 bit platform) and -263 to 263-1 (64-bit platform).
Float is a single-precision, floating-point value. Range of float is 1.2 x 10-38 to 3.4 x 1038 (Up to 6 decimal places)
Double is a double-precision, floating point value. Range of a double value is 2.3 x 10-308 to 1.7 x 10308 (Up to 15 decimal places).
Bool is a simple value type that consists of two possible cases: true or false.
SWIFT COLLECTION TYPES
There are 3 primary collection data types in Swift: Set, Array and Dictionary.Set is a collection of unordered unique values. Value distinction is determined by it’s hash value. A value that needs to be stored in a Set must conform to Hashable protocol. A hash value is an integer and it is the same for all object that compares equally.
Array is an ordered collection of values of the same type. The same value of an array can appear multiple times in this collection, at a different place.
Dictionary is an unordered collection of values that are accessed by their keys. Dictionaries store the associations between the keys of the same type and values of the same type. Each value is associated with it’s unique key, which acts as the “identifier” or “accessor” for the associated value.
Comments
Post a Comment