-
- Any can represent an instance of any type at all, including function types and optional types.
- Any is used for all types
- AnyObject can represent an instance of any class type.
- AnyObject is used for Class types, right?
Example of Any:let arr:[Any] = [1,2,"params","tamil"]print(arr)
Output:[1,2,params,tamil]Example of AnyObject:let arr1:[AnyObject] = [1 as AnyObject,2 as AnyObject,"parameswaran" as AnyObject,"tamil" as AnyObject]print(arr1)Output:[1,2,parameswaran,tamil]
Closures are self contained chunks of code that can be passed around and used in your code. Closures can capture and store references to any constants or variables from the context in which they are defined. This is know as closing over those variables, hence the name closures. Closures are use intensively in the Cocoa frameworks – which are used to develop iOS or Mac applications. Functions are a special kind of closures. There are three kinds of closures: global functions – they have a name and cannot capture any values nested functions – they have a name and can capture values from their enclosing functions closure expressions – they don’t have a name and can capture values from their context The thing to keep in mind for the moment is that you already have an intuition about closures. They are almost the same as functions but don’t necessarily have a name. // a closure that has no parameters and return a String var hello: () -> ( String ) = { ...
Comments
Post a Comment