Skip to content

Marshaling Date? #139

@JetForMe

Description

@JetForMe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions