| 1. |
What do you mean by property in iOS? |
|
Answer» Properties are basically values that are associated with a class, struct, or enum. They can be THOUGHT of as "sub-variables," i.e., parts of another object. Example: struct Icecream { var flavor: String = ""} var choco = Icecream() choco.flavor = "Chocolate Icecream"In the above code, we created a structure called Icecream. One of its properties is called flavor, a String whose initial value is empty. Classification of Properties
Example: class Programmer { var progName: String let progLanguage: String var totalExperience = 0 var secondLanguage: String?}Above, the Programmer class defines four stored properties: progName, progLanguage, totalExperience, and secondLanguage. These are all stored properties since they can contain values that are part of the instance of the class. The above example shows properties with and without default values, as well as an optional one.
Example: struct Angle { var degrees: Double = 0 var rads: Double { get { return degrees * .pi / 180 } set(NEWRADS) { degrees = newRads * 180 / .pi } }}As mentioned above, the angle structure has a stored property called degrees for storing angles in degrees. Moreover, angles can also be expressed in radians, so the Angle structure contains a Rads property, which is a computed property. |
|