Learn Courses My Dashboard

Insert 'from: <#Decoder#>'


------------------------->HERE is the Class:

class Stock: Codable {
var metaData: MetaData
var timeSeries5Min: [String: TimeSeries5Min]

enum CodingKeys: String, CodingKey {
    case metaData = "Meta Data"
    case timeSeries5Min = "Time Series (5min)"


class MetaData: Codable {
var information, symbol, lastRefreshed, interval,outputSize: String
var timeZone: String

enum CodingKeys: String, CodingKey {
    case information = "1. Information"
    case symbol = "2. Symbol"
    case lastRefreshed = "3. Last Refreshed"
    case interval = "4. Interval"
    case outputSize = "5. Output Size"
    case timeZone = "6. Time Zone"


class TimeSeries5Min: Codable {
var open, high, low, close: String
var volume: String

enum CodingKeys: String, CodingKey {
    case open = "1. open"
    case high = "2. high"
    case low = "3. low"
    case close = "4. close"
    case volume = "5. volume"


--------------->HERE is the Error

@Published var stock = Stock()

Missing argument for parameter ‘from’ in call,
Insert ‘from: <#Decoder#>’

That error is because you are trying to initialize a Stock object but have not provided the correct parameters.

The Decodable protocol (which is part of Codable) requires an init that takes a decoder as a parameter:

/// A type that can decode itself from an external representation.
public protocol Decodable {

    /// Creates a new instance by decoding from the given decoder.
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    /// - Parameter decoder: The decoder to read data from.
    init(from decoder: Decoder) throws

If you use a struct, you can skip this initializer and just use the default memberwise init.

If you show more of your ObservableObject class where the error occurs, I’m sure someone on these forums could help you figure out a better way of doing what you’re trying to do. For one thing, you almost certainly should make your Codable objects as structs instead of classes.

1 Like

Thank you, I would have answered faster but a few minutes ago I received an email with your response. I ll come back with more, because I am really stuck here.