Esqarrouth/EZSwiftExtensions

Swift 3 Ambiguous use of .month .day .year

otymartin opened this issue · 5 comments

These were working well in version 1.7 but version 1.8 spits out error Ambigous use of....

    var dateOfBirth: Date?
     ...
//Date of Birth
    var DOBMonth: Int {
        return (self.dateOfBirth?.month)!
    }
    
    var DOBDay: Int {
        return (self.dateOfBirth?.day)!
    }
    
    var DOBYear: Int {
        return (self.dateOfBirth?.year)!
    }

I tried reproducing your issue.

let dateOfBirth = Date()
print(dateOfBirth.month)
print(dateOfBirth.day)
print(dateOfBirth.year)

And I was able to successfully get

1
2
2017

Which is as expected. Breakpoints revealed the right extensions are called.

These extensions were added as a part of release v1.8 in PR #313.

I suspect you are using extension from a conflicting library prior to your update or writing your own custom extension for the same.

Let me know if this helps.

@Khalian Your right, it was conflicting with SwiftDate. Can this be solved without deleting swiftdate?

//SWIFTDATE
public extention Date {

/// The number of year units for the receiver expressed in the context of `defaultRegion`.
	public var year: Int {
		return self.inDateDefaultRegion().year
	}
	
	/// The number of month units for the receiver expressed in the context of `defaultRegion`.
	public var month: Int {
		return self.inDateDefaultRegion().month
	}
	
	/// The number of day units for the receiver expressed in the context of `defaultRegion`.
	public var day: Int {
		return self.inDateDefaultRegion().day
	}
}

Ok. I suspected as such.

We made many additions to Date. You can refer to them in https://github.com/goktugyil/EZSwiftExtensions/blob/master/CHANGELOG.md. If they cover your all your use cases, you can remove the dependency from SwiftDate and consume EZSwiftExtensions exclusively.

Otherwise you might have to resolve them like this : http://stackoverflow.com/questions/33892897/name-collisions-for-extension-methods-from-different-frameworks

@Khalian Yea I must just go that route. Thanks

@otymartin No problem happy to help.