-1

I am trying to access a class method from another class but I am getting error. I have a class 'Constants' in which I have written a class method 'changeDateFormat' and accessing it from some viewController. Here is my code.

Constants.h

@interface Constants : NSObject

+(NSString *)changeDateFormat:(NSString *)currentDate;

@end

Constans.m

@implementation Constants

+(NSString *)changeDateFormat: (NSString *) currentDate
{
    NSString *convertedDate = @"";
    @try
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"MMM dd yyyy"];
        NSDate *date = [dateFormatter dateFromString:currentDate];

        NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
        [dateFormatter1 setDateFormat:@"yyyy-mm-dd"];

        convertedDate = [dateFormatter1 stringFromDate:date];
    }
    @catch(NSException *e)
    {
        NSLog(@"%@ %@", e.name, e.reason);
    }
    return convertedDate;
}

@end

I am trying to access the above method like Constants.changeDateFormat:@"Mar 11 2018" but I am getting error - Property not found on object of type.

Palash Bairagi
  • 71
  • 1
  • 1
  • 8

1 Answers1

1

You are sending the changeDateFormat: method. You don't use a . for that. This is the correct syntax:

NSString *output = [Constants changeDateFormat:input];
rob mayoff
  • 375,296
  • 67
  • 796
  • 848