Reputation: 12621
I need to call a method that has been defined in the same class.I am calling the method initiateSession from the function A.
-(BOOL)intitiateSession
{
//stmts
return YES;
}
-(BOOL)A
{
if([self initiateSession])
{
//stmts
}
return YES;
}
getting a runtime error as,
Terminating app due to uncaught exception
cannot init a class object
@implementation Data
-(BOOL)initiateSession
{
NSLog(@"I am into the initiateSession!!");
return YES;
}
-(BOOL)getNHPData{
NSLog(@"In getNHPData!!");
if([self initiateSession])
{
NSLog(@"I am into the session");
}
return YES;
}
@end
Here in the if loop i will call the function.Execute the function and if the function
executes to true i'm getting inside the scope.I could not able to call one function from
other function.
Upvotes: 0
Views: 6608
Reputation: 299265
getNHPData()
is not an initializer and should not be calling [super init]
. That is something you would call from within your own initializer. Your code as written will not even compile (your @implementation
line is incorrect). You are certainly receiving many warnings in the above code that you should be listening to (you're returning self
from a BOOL method in one case, and have no return
in the other case). Your actual error suggests you're doing something like [Data getNHPData]
which is not legal since getNHPData
is an instance method. You should be getting warnings about that as well.
First, clean up all your warnings. That will probably get you moving in the right direction. Cocoadevcentral has a quick intro to all the issues you're running into.
Upvotes: 3