Browse Questions
  • Both manage concurrent work, but async/await (introduced in Swift 5.5) is structured and compiler-checked, while GCD is unstructured and callback-based.
  • Classic OOP assumes objects are reference types with identity and shared mutable state.
  • A memory leak is memory that is allocated but never freed — usually from retain cycles.
  • some declares an opaque return type — the function returns a specific concrete type that conforms to a protocol, but the caller doesn't need to know which type it is.

Answer: some declares an opaque return type — the function returns a specific concrete type that conforms to a protocol, but the caller doesn't need to know which type it is. Used heavily in SwiftUI's body: some View.

Code Example:

// Without some — must specify exact type (often impossible with complex views)
func makeView() -> VStack<TupleView<(Text, Text)>> { ... } // ugly

// With some — hides the concrete type
func makeView() -> some View {
    VStack {
        Text("Hello")
        Text("World")
    }
}

// Also useful for protocols with associated types
protocol Shape {
    func area() -> Double
}

func makeShape() -> some Shape {
    Circle(radius: 5)
}

Key difference from any: some is a specific type (compiler-optimized), any is a type-erased existential (runtime overhead).