FlashKeepers

Swift · College · College and University

Swift III: Closures, Errors and ARC

Closures, higher-order functions, throws and try, Result, ARC, retain cycles and weak or unowned references.

About this set

40 basic cards for College Swift. Set 3 of 4 in Swift. It opens with "What is a closure in Swift?" and "What is the simplest closure syntax?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a closure in Swift?
Show answerA self-contained block of functionality that captures and stores references to variables and constants from its surrounding context.
What is the simplest closure syntax?
Show answer{ parameters in statements }
What does it mean for a closure to capture a value?
Show answerThe closure stores a reference to a variable or constant from its surrounding scope, allowing access even after the scope ends.
What is an escaping closure?
Show answerA closure called after the function it was passed to returns, escaping the function's scope.
What does @escaping indicate?
Show answerA closure parameter that may be called after the function returns, so it escapes the function's scope.
What is a trailing closure?
Show answerA closure passed as the last argument to a function, written outside the parentheses for readability.
How do closures differ from named functions?
Show answerClosures are unnamed blocks that capture surrounding context; functions are named and do not capture context by default.
Can closures have explicit return types?
Show answerYes, written as { (parameters) -> ReturnType in statements }.
What is an autoclosure?
Show answerA closure automatically created to wrap an expression, marked with @autoclosure, allowing you to omit braces.
What is a non-escaping closure?
Show answerA closure guaranteed to be called before the function returns, unable to escape the function's scope (the default).
What is a higher-order function?
Show answerA function that takes one or more functions as arguments or returns a function as its result.
What does map do?
Show answerTransforms each element in a collection using a closure and returns a new array with the transformed elements.
What does filter do?
Show answerReturns a new array containing only the elements that satisfy the condition in the closure.
What does reduce do?
Show answerCombines all elements into a single value by applying a closure that takes an accumulated value and the next element.
What does sorted do?
Show answerReturns a new array with elements sorted according to the closure that compares two elements.

25 more cards in the app

Study this set free