ANS : Swift has 2 types for working with nonspecific type.
1. AnyObject
2. Any
1. AnyObject
2. Any
1. AnyObject is for reference type(class) and Any is for both reference and value type.
2. AnyObject represent instance of only any class type, Any represent for any type including function type.
Note : It is always good practice to use specific type instead of Any, AnyObject.
After Swift 3.0, Objective C I'd type can be compatible with Swift Any type. Before that it is equivalent to AnyObject.
I.e
I have created dictionary in which I don't know what will be Value type.
[String : ?? ]
then ?? may be int, float, Array, Dictionary type.
So here we should use Any in replace of ??, because int, float are value type and array, dictionary are class type.
[ String : Any]
No comments:
Post a Comment
Thanks