Thursday 3 November 2016

Completion Handler Closures In Swift3.0

Closures in Swift are similar to blocks in Objective-C.Closures are self-contained blocks of functionality that can be passed around and used in your code.Closures can capture and store references to any constants and variables from the context in which they are defined.

Closure Syntax:

  • { (parameters) -> return type in
  •     statements
  • }
  • We can pass  in-out parameters, but they can’t have a default value. Variadic parameters can be used if you name the variadic parameter. Tuples can also be used as parameter types and return types.
    Completion Handler In Swift3.0
    Steps1)
    • Take a SingleView Application.Now create a new file and name it Test.swift



















      • 2)After adding this class I have declare
        •  completionHandler and also created a function named "getFullName". TestCompletionHandler is passed in that function as a parameter. This completion handler having two parameters.
                                                                                                                      

No comments:

Post a Comment