boredzo / iso-8601-date-formatter

A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.
http://boredzo.org/iso8601dateformatter/
Other
600 stars 140 forks source link

'ISO8601DateFormatter' is ambiguous for type lookup in this context #76

Open marcelofabri opened 8 years ago

marcelofabri commented 8 years ago

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.

johnboyer commented 8 years ago

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.

heymansmile commented 7 years ago

@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
marcelofabri commented 7 years ago

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

rz-robsn commented 7 years ago

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.

johnboyer commented 7 years ago

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