Help "Type 'Account_Admin' does not conform to protocol 'Decodable'" "Type 'Account_Admin' does not conform to protocol 'Encodable'" "Type 'Account_Admin' does not conform to protocol 'Decodable'"

When i try to run this code i get "Type 'Account_Admin' does not conform to protocol 'Decodable'" "Type 'Account_Admin' does not conform to protocol 'Encodable'" "Type 'Account_Admin' does not conform to protocol 'Decodable'" Swift code:

import SwiftUI

public var islogged: Bool = false
struct Account_Admin: Hashable, Codable, Identifiable{
  var id: Int
  var name: String
  var nickname: String
  var age: Int
  var purchases: Int
  var isinguestac: Bool
  var tickies: Int
  var profilepic: Image
  var role: Role
  enum Role: String, CaseIterable, Codable{
    case Admin = "Admin"
    case Developer = "Developer"
    case Manager = "Manager"
    case Designer = "Designer"
  }
  private var imagename: String
  var image: Image{
    Image(imagename)
  }
}
Answered by Claude31 in 745373022

Welcome to the forum

What a long thread title for a simple question! A simpler title would be "How to make this struct conform to Codable?"

Problem is that Image does not conform to Codable.

Find a way to solve it here, by having Data in the struct, from which you build the image: https://stackoverflow.com/questions/60209432/swift-how-to-conform-this-struct-to-codable

Note in Swift, you should use camelCase convention

var profilePic: Image
Accepted Answer

Welcome to the forum

What a long thread title for a simple question! A simpler title would be "How to make this struct conform to Codable?"

Problem is that Image does not conform to Codable.

Find a way to solve it here, by having Data in the struct, from which you build the image: https://stackoverflow.com/questions/60209432/swift-how-to-conform-this-struct-to-codable

Note in Swift, you should use camelCase convention

var profilePic: Image
Help "Type 'Account_Admin' does not conform to protocol 'Decodable'" "Type 'Account_Admin' does not conform to protocol 'Encodable'" "Type 'Account_Admin' does not conform to protocol 'Decodable'"
 
 
Q