In my application I am working on a module of converting string to MMMM yyyy date format and insert it in database
Input:- NSString which may be of MMMM yyyy or dd/MM/yyyy hh:mm:ss format
Output:- NSString with MMMM yyyy format
And I Implement method like below
-(NSString *)convertToRequiredDataString:(NSString *)downloadedString
{
NSString *stringToInsert=downloadedString;
NSArray *checkArray=[stringToInsert componentsSeparatedByString:@"/"];
if (checkArray.count>=2) {
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd/MM/yyyy 00:00:00"];
NSDate *date=[formatter dateFromString:stringToInsert];
[formatter setDateFormat:@"MMMM yyyy"];
stringToInsert=[formatter stringFromDate:date];
if (!stringToInsert) {
stringToInsert=@"";
}
}
return stringToInsert;
}
My question is that, Instead of checking the array length as checkArray.count>=2 is there any logically correct way of implementation possible