Swift has two anonymous types “Any” and “AnyObject”.
Any can represent any type at all including function type and optional type.
AnyObject can represent any class type.
Swift provides two nonspecific types called any and anyobject.
AnyObject is used for class types.
The protocol to which all classes implicitly conform.
You use AnyObject when you need the flexibility of an untyped object or when you use bridged Objective-C methods and properties that return an untyped result.
AnyObject can also be used the concrete type for a type that bridges to an Objective-C class. Many value types in Swift bridge to Objective-C, like string and int.
Any is used for all types. Any allowed to work with a mix of different types including function and non-class types such as int, string, and bool. According to the elements in this array are structs are value types, so in theory, AnyObject should not work in these cases.
Any is used for all types. Any allowed to work with a mix of different types including function and non-class types such as int, string, and bool. According to the elements in this array are structs are value types, so in theory, AnyObject should not work in these cases.
Let’s make a quick comparison. Consider that a constantly called age has value 20 and is of type Int.
This type Int is specific - we are very clear here about the fact that age is an integer number.
Now let’s check out a nonspecific type that uses Any. The following code defines a values array of type [Any] :
android development blog
1 day ago
IOS development blog
2 days ago
Graphic Designer blog
2 days ago
react native development blog
3 days ago