Reputation: 232
I am working on an iphone app with push notifications. My question is how to call a function from a classB when i receive a push notification without creating an instance of that classB nor using static method?
Many thanks :)
Upvotes: 0
Views: 760
Reputation: 122458
You will need to hold a reference to classB from within the object that receives the push notification:
// The header file of the class that receives the notification
@class classB;
@interface MyNotifiedClass : NSObject
{
classB *_classB;
}
@property (retain, nonatomic, readwrite) classB *classB;
// The implementation file of the class that receives the notification
@implementation MyNotifiedClass
....
@synthesize classB = _classB;
- (void)theMethodThatReceivesTheNotification:(whatever)
{
[_classB doSomethingNowPlease];
}
You will obviously have to set the instance of classB
in this class before it will work:
// Someplace outside both classes (assuming _classB points to an instance of classB
// and _myNotifiedClass points to an instance of MyNotifiedClass)
[_myNotifiedClass setClassB:_classB];
Upvotes: 1
Reputation: 15213
There is no way to call an instance method of a class without instantiating it. Your solution is either calling a class method or classB
could have singleton initializer.
Upvotes: 0