Search code examples
iosobjective-coopios7azure-mobile-services

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/"
                                      applicationKey:@"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 nil

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


Solution

  • 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.