Junior
What data types exist in Swift?
sobes.tech AI
Answer from AI
In Swift, the following main data types exist:
- Primitive types:
- Integer types:
Int(default, platform-dependent),Int8,Int16,Int32,Int64, and their unsigned counterpartsUInt8,UInt16,UInt32,UInt64. - Floating point:
Float(32-bit representation),Double(64-bit representation, default). - Boolean values:
Bool(takes valuestrueorfalse).
- Integer types:
- Strings and Characters:
String,Character. - Collections:
- Arrays:
Array(ordered collection allowing duplicates). - Sets:
Set(unordered collection of unique values). - Dictionaries:
Dictionary(unordered collection of key-value pairs, where keys are unique).
- Arrays:
- Tuples:
Tuple(grouping multiple values of different types into a single composite value). - Optional types:
Optional(represents either a value of a certain type or absence of a value (nil)). - Structures:
struct(value types).struct Point { var x: Int var y: Int } - Classes:
class(reference types).class Person { var name: String init(name: String) { self.name = name } } - Enumerations:
enum(group of related values).enum Direction { case up, down, left, right } - Function types:
(Parameters) -> ReturnType(represent closures and functions).let greeting: (String) -> String = { name in return "Hello, \(name)!" }