-
- 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]
Enums An enum is considered as a structured data type that can be modified without needing to change say a String or Int multiple times within your code, for example the below shows how easy it would be to change something by accident and forget to change it somewhere else. let myString = "test" if myString == "ttest" { // Doesn't execute because "ttest" is the value assigned to "myString" } With a enum we can avoid this and never have to worry about changing the same thing more than once enum MyEnum : String { case Test = "test" } let enumValue = MyEnum . Test if enumValue == MyEnum . Test { // Will execute because we can reassign the value of "MyEnum.Test" unless we do so within "MyEnum" } Structs I'm not sure how much you know about the MVC pattern but in Swift this is a common practise, before I explain how structs are useful I'll...
Comments
Post a Comment