I am working with core-graphics
and in my app I am drawing different type of shapes and manipulating them. So I have around 150 UIView
objects(shapes) which can be chosen by user.
I have a NSObject
class, which has sliders to change the size of shapes. So I am passing the view instance from every UIView
to this NSObject
class to modify there size.
In NSObject
class I have a function like below:
-(id) initWithView:(id)shapeView
{
...
}
So at run time when user choose a shape and move the slider that shape's instance is passed to this function in NSObject
class. Now I can manipulate the size of the particular "shapeView".
But the problem is I can't access functions of UIView
class to which it belongs.
I can't use something like below because type of shapeView is unknown at compile time and it throws error:
[shapeView someFunction:];
For example user chooses a Rectangle in app. Then the Class type of shapeView is Rectangle. I can find out this using [view class]
. So I can modify the size of rectangle but can't access its functions. To access function I have to declare a instance of type Rectangle
in NSObject
class. So my question is how to extract the Class name from a instance (shapeView in this case) and declare a instance of that class type.
I know one way is to check type of every type of UIView
class and then make instance accordingly. But as I said there are 150 UIView
classes and in future I will add more to it. So is there any other way around to solve this problem?