1. Type Safety: Swift is a type-safe language, which means that every variable and constant needs to be declared with a specific type. For example, if you declare a constant like this: let age = 25, then it will always be an integer.

2. Closures: Closures are self-contained blocks of code that can be passed around and used in your code. For example, you can use a closure to sort an array of numbers like this:

let sortedNumbers = numbers.sorted { (num1, num2) -> Bool in
return num1 < num2
}

3. Optionals: Optionals are a way to handle the absence of a value. For example, if you have an optional string called name, you can check if it has a value like this:

if let name = name {
print("Hello, (name)")
}

4. Generics: Generics allow you to write flexible and reusable functions and types. For example, you can write a generic function to swap two values like this:

func swap(_ a: inout T, _ b: inout T) {
let temp = a
a = b
b = temp
}

5. Memory Management: Swift uses Automatic Reference Counting (ARC) to manage memory. This means that you don’t have to manually manage memory like you do in other languages. For example, when you create an object, ARC will automatically release it when it is no longer needed.

Leave a Reply

Your email address will not be published. Required fields are marked *