iso-8601-date-formatter icon indicating copy to clipboard operation
iso-8601-date-formatter copied to clipboard

'ISO8601DateFormatter' is ambiguous for type lookup in this context

Open marcelofabri opened this issue 8 years ago • 5 comments

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.

marcelofabri avatar Oct 05 '16 15:10 marcelofabri

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.

johnboyer avatar Oct 05 '16 16:10 johnboyer

@marcelofabri There is the easy fix (XCode 8, Swift 3.0):

  1. Exclude import declaration: import Foundation
  2. Import class: import class ISO8601DateFormatter.ISO8601DateFormatter
  3. The class is available simple as ISO8601DateFormatter and the apple's one as Foundation.ISO8601DateFormatter

heymansmile avatar Oct 21 '16 04:10 heymansmile

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

marcelofabri avatar Oct 21 '16 15:10 marcelofabri

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.

rz-robsn avatar Apr 13 '17 15:04 rz-robsn

If you’re using iOS 10, I’d recommend migrating to NSISO8601DateFormatter and ISO8601DateFormatter in Objective-C and Swift, respectively.

johnboyer avatar Apr 15 '17 18:04 johnboyer