Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshaling Date? #139

Open
JetForMe opened this issue May 9, 2019 · 0 comments
Open

Marshaling Date? #139

JetForMe opened this issue May 9, 2019 · 0 comments

Comments

@JetForMe
Copy link
Contributor

JetForMe commented May 9, 2019

So, it's clear to me how to unmarshal a Date, by extending it with the ValueType protocol. But it's not at all clear how to marshal it. I tried various forms of this:

extension
Date : ValueType, Marshaling
{
	public
	static
	func
	value(from inObj: Any)
		throws
		-> Date
	{
		guard
			let timeInterval = inObj as? Double
		else
		{
			throw MarshalError.typeMismatch(expected: Double.self, actual: type(of: inObj))
		}
		
		let date = Date(timeIntervalSinceReferenceDate: timeInterval)
		return date
	}
	
	public
	func
	marshaled()
		-> Double
	{
		return self.timeIntervalSinceReferenceDate
	}
}

But Xcode doesn't like it. In this case, it says Type 'Date' does not conform to protocol 'Marshaling'. Not sure what I'm doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant