Class Warfare
The point of this task is getting to know the Objective-C anonymous data type, id, and to learn how to control it. This task is a view-based application which initially has a single button called “Random View”. When the button is pressed, a random anonymous object is created and based on the type of the object, the application operates as follows:
The point here is taking advantage of ,
- If the object is a UIView class or subclass thereof, it is added as a subview to the main view.
- If the object has a background colour property, it is given a random colour before being added to the main view.
The point here is taking advantage of ,
isKindOfClassor
isMemberOfClassto determine the dynamic type of the object, and
respondsToSelectorto see if it has a background colour property or not. The code snippet below shows the IBAction method controlling the “Random View” button.
No comments:
Post a Comment