yevh
(Yevhenii)
January 19, 2020, 12:21am
1
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.
griotspeak
(TJ Usiyan)
January 19, 2020, 12:26am
3
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
jonprescott
(Jonathan Prescott)
January 19, 2020, 12:26am
4
Why did you not use UserResponse.name?
That would not work as the type UserResponse does not have a name property, only instances of that type.