iso-8601-date-formatter
iso-8601-date-formatter copied to clipboard
'ISO8601DateFormatter' is ambiguous for type lookup in this context
I'm updating my project to use Swift 3.0 and on 3.0 , NSISO8601DateFormatter
becomes just ISO8601DateFormatter
, which conflicts with this library.
Unfortunately, using ISO8601DateFormatter.ISO8601DateFormatter
doesn't help either (seems to be a compiler bug: https://bugs.swift.org/browse/SR-1386).
An easy way to fix this would be using module_name
in the Podspec (https://guides.cocoapods.org/syntax/podspec.html#module_name) to change the module to something else, allowing SomeModule.ISO8601DateFormatter
.
I’d like to suggest that perhaps this project should be a changed to category in Objective-C and an extension in Swift. We’ve unit tested Apple’s new NSISO8601DateFormatter
against this library and have determined that theNSISO8601DateFormatter
meets our needs. Therefore, we’re planning replace to ISO8601DateFormatter
with the NSISO8601DateFormatter
class when we upgrade our codebase to iOS 10. We also plan to use Apple’s ISO8601DateFormatter
in new projects using Swift 3.0.
@marcelofabri There is the easy fix (XCode 8, Swift 3.0):
-
Exclude import declaration:
import Foundation
- Import class:
import class ISO8601DateFormatter.ISO8601DateFormatter
- The class is available simple as
ISO8601DateFormatter
and the apple's one asFoundation.ISO8601DateFormatter
I needed Foundation
on that file, so I've come up with another workaround:
// Fixes 'ISO8601DateFormatter' is ambiguous for type lookup in this context
// see http://stackoverflow.com/questions/36991735/how-to-reference-a-type-in-a-module-that-has-a-type-with-the-same-name-as-the-mo
import class ISO8601DateFormatter.ISO8601DateFormatter
typealias SomePrefixISO8601DateFormatter = ISO8601DateFormatter
Then I just used SomePrefixISO8601DateFormatter
instead of ISO8601DateFormatter
on other files
May I suggest to simply add a 3-letter prefix to the ISO8601DateFormatter
class ? This would be consistent with Apple's Objective-C Naming Convention.
This library would have never had this issue if it followed the 3-letter prefix rule, which was introduced to specifically to avoid name clashes like this one.
If you’re using iOS 10, I’d recommend migrating to NSISO8601DateFormatter
and ISO8601DateFormatter
in Objective-C and Swift, respectively.