You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try container.encode(value, forKey:.value)// ERROR: Reference to member 'value' cannot be resolved without a contextual type
That's because the value property is of type Optional<Any>. Prior to Swift 4.1 Optional conformed to the Encodable protocol unconditionally at compile time, but attempting to encode its payload if the payload is not itself Encodablewould crash at runtime.
Swift 4.1 introduced conditional conformances, and now this error is caught at compile time, which results in the inability to compile Swiftgger.
My suggestion would be to make the OpenAPIExample class generic:
-public class OpenAPIExample: Encodable+public class OpenAPIExample<Value: Encodable>: Encodable {
public private(set) var ref: String?
public private(set) var summary: String?
public private(set) var description: String?
- public private(set) var value: Any?+ public private(set) var value: Value?
public private(set) var externalValue: String?
However, I haven't tried this and not sure if it'll work with the rest of the project.
I'm looking forward to be able to use Swiftgger in my Vapor project 😊
The text was updated successfully, but these errors were encountered:
The library cannot be compiled with Swift 4.1 because of the error in
OpenAPIExample.swift
, line 47:That's because the
value
property is of typeOptional<Any>
. Prior to Swift 4.1Optional
conformed to theEncodable
protocol unconditionally at compile time, but attempting to encode its payload if the payload is not itselfEncodable
would crash at runtime.Swift 4.1 introduced conditional conformances, and now this error is caught at compile time, which results in the inability to compile Swiftgger.
My suggestion would be to make the
OpenAPIExample
class generic:However, I haven't tried this and not sure if it'll work with the rest of the project.
I'm looking forward to be able to use Swiftgger in my Vapor project 😊
The text was updated successfully, but these errors were encountered: