Jay Mayu Jay Mayu - 9 months ago 37
iOS Question

Objective C calling method from another call

I have created a class AuthService

in AuthService declaration I have this

- (MSClient *) getClient;

and in the implementation (.m file) I have this

- (MSClient *) getClient{
client =[MSClient clientWithApplicationURLString:@"XXXXXXX/"
return client;

Now I'm tring to get the instance of the MSClient in a view controller during a button click as below.

AuthSerivce class is initialised like this in .h file first

@property (strong, nonatomic) AuthService *authService;

client is declared as MSClient object and sythesized as below

@synthesize client;

Then I tried to create a client object from the AuthService class (yeap I refered AuthService.h in the view controller)

client = [authService getClient];

But my problem is that, getClient is always returning

I'm sure I'm missing something in basic objective c OOP conceps. Please correct me.

Answer Source

Declaring a property does not initialize it. So this line,

@property (strong, nonatomic) AuthService *authService;

doesn't create an instance of AuthService, you need to alloc init one before you can call getClient.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download