Error ‘Value of type has no subscripts’ help pls

I have the next class in the file UserResponse.swift

import Foundation

import UIKit

import SwiftUI

struct UserResponse: Hashable, Codable, Identifiable {

var id: Int

var name: String

var profileImage: String

var email: String

var likes: String

var text: String


And I used it in another file and error appear for this ’ Value of type UserResponse[1] has no subscripts’

struct Cell_Previews: PreviewProvider {

static var previews: some View {

 Cell(user: UserResponse[1])



Could anyone help pls?!

If you post code excerpts between triple-backticks, you don’t have to try to manually code-format them.

At first glance… it is really just what it says on the tin. It looks like you're trying to subscript into the type UserResponse I am going to guess that you mean to have an array named userResponses (note the lowercase "u") or something similar and you want the second item in the array?

1 Like

Why did you not use

That would not work as the type UserResponse does not have a name property, only instances of that type.