</>
Skip to content
Swift lessons (26/33)

Swift — Extensions

Basic extension

extension String {
    func reversed() -> String {
        return String(self.reversed())
    }
}

Add method

extension Int {
    func squared() -> Int {
        return self * self
    }
}

let x = 5.squared()  // 25

Mini Practice

  1. Create extension
  2. Add methods
  3. Add computed properties
  4. Practice extensions

Up Next

Continue with Memory Management - ARC.

Related Topics

Frequently Asked Questions about Extensions

What is Extensions in Swift?

Extensions is a fundamental concept in Swift. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Extensions?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Extensions.

Why is Extensions important in Swift?

Extensions is essential for Swift development. Understanding this concept will help you write better code and solve real-world problems more effectively.