I have 2 classes, say class A and class B. Class B is created in class A. I have a method in class A, which needs to be executed in both class A and class B. Calling the method in class A itself is fine. But I am not sure about calling the method in class B. I have tried declaring the method as static, but since I can't use instance variables inside the static method, I think using delegates would be a good idea. Since I am from a C# background, I am not sure about using it in Objective C. Conceptually, I have implemented what I need in C# as shown below. Just wanted to know what the equivalent of it would be in Objective C.
class A
{
public A()
{
B myclass = new B(() => calculate());
}
public void calculate()
{
// todo
}
}
class B
{
public B(Action calculate)
{
calculate();
}
}
Is it possible to do this using protocols.
See Question&Answers more detail:os