Swift has a variety of basic data types to represent different kinds of values. Here's a table summarizing them, along with their typical sizes and value ranges:

32-bit Int: -2,147,483,648 to 2,147,483,647

64-bit Int: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807


Data TypeDescriptionSize (bits)Range/ValuesExample
Numeric
IntSigned integer (platform dependent)32 or 64-2^31 to (2^31)-1 (32-bit)
-2^63 to (2^63)-1 (64-bit)
10, -5, 1234567890
Int8Signed integer8-128 to 12710, -5
Int16Signed integer16-32768 to 3276710000, -2000
Int32Signed integer32-2,147,483,648 to 2,147,483,647123456789, -1000000
Int64Signed integer64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8071000000000000, -5000000000
UIntUnsigned integer (platform dependent)32 or 640 to (2^32)-1 (32-bit)
0 to (2^64)-1 (64-bit)
10, 1234567890
UInt8Unsigned integer80 to 25510, 200
UInt16Unsigned integer160 to 6553510000, 60000
UInt32Unsigned integer320 to 4,294,967,295123456789, 4000000000
UInt64Unsigned integer640 to 18,446,744,073,709,551,6151000000000000, 10000000000000
FloatFloating-point32±1.40129846432481707e-45 to ±3.40282346638528860e+38 (~6 decimal digits precision)3.14f, -2.5f
DoubleFloating-point64±4.94065645841246544e-324 to ±1.79769313486231570e+308 (~15 decimal digits precision)3.14159, -2.71828
Text
CharacterSingle characterVariable (UTF-8 encoding)Any valid Unicode character'a', '?', '한'
StringSequence of charactersVariable (UTF-8 encoding)"Hello", "Swift"
Boolean
BoolBoolean value8true, false
Other
ArrayOrdered collection of elements of the same typeVariable[1, 2, 3], ["a", "b"]
DictionaryCollection of key-value pairsVariable["name": "Alice", "age": 30]
SetUnordered collection of unique elementsVariable[1, 2, 3]
OptionalRepresents a value that may be absent (nil)let optionalInt: Int? = nil
  • Size: The size of String, Array, Dictionary, and Set types is dynamic and depends on the content.
  • Integer size: Swift provides both platform-dependent (Int, UInt) and fixed-size integer types. Use the platform-dependent ones for most cases, as they are optimized for the current system.
  • Character size: Swift uses UTF-8 encoding for characters, so the size of a Character can vary depending on the character.

This table provides a good overview of Swift's basic data types. Remember that efficient memory management is handled by Swift's Automatic Reference Counting (ARC), so you usually don't need to worry about the exact size of these types in your everyday coding.