[Solved] How do I convert a parameterised enum/ enum with associated values from Swift to Objective-C? [closed]


Let me explain your code for you:

NSString *isoFormat = ISO8601DateFormatType;

(assigns string ISO8601 to isoFormat)

NSString *dateFormat = (isoFormat != nil) ? isoFormat : ISO8601DateFormatType;

(isoFormat is never nil so the condition is always true. If it were false, we would again assign string ISO8601).

NSDateFormatter *formatter = ... 

(we get some formatter, it doesn’t matter how because we are overwriting all its important properties anyway)

formatter.locale = [NSLocale localeWithLocaleIdentifier: (@"en_US_POSIX")];

(let’s overwrite the [NSLocale currentLocale] above with POSIX locale, that’s fine)

formatter.timeZone = [NSTimeZone localTimeZone];

(let’s set time zone again)

formatter.dateFormat = dateFormat;

(let’s set string ISO8601 to be the date format, this is not a valid date format)

NSDate *date = [formatter dateFromString:(string)];

(let’s try to parse a date using an invalid date format ISO8601. Obviously, this will return nil)

In short – the problem is exactly the same as the problem in your previous question Error in dateFormat returns nil

3

solved How do I convert a parameterised enum/ enum with associated values from Swift to Objective-C? [closed]