Blocks in swift – what are blocks in swift ?

By | July 16, 2016

Blocks in swift – what are blocks in swift ?

An Objective-C class defines an object that combines data with related behavior. Sometimes, it makes sense just to represent a single task or unit of behavior, rather than a collection of methods.

Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray orNSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures or lambdas in other programming languages.