Xcode Preview not showing

I was following a YouTube tutorial about how to connect my django backend to Swift and when I finished following along, I just get a blank grey area where the phone preview should be. Anyone know why this would happen? Here's my Model file and my View.

import Foundation

struct Account: Codable, Hashable {
    var email: String
    var username: String
    var first_name: String
    var last_name: String
    var is_venue: Bool
    var date_joined: Date
    var last_login: Date
    var is_active: Bool
    var is_admin: Bool
    var is_superuser: Bool
}

And View

import SwiftUI
struct AccountView: View {
@State var accounts = [Account]()

var body: some View {
    ForEach(accounts, id: \.self) {item in
    HStack {
        Text(item.first_name)
    }
    }.onAppear(perform: loadAccount)
}
func loadAccount() {
    guard let url = URL(string: "http://127.0.0.1:8000/api/account/") // URL is the endpoint of API
    else {
        print("API is down")
        return
    }
    
    var request = URLRequest(url: url)
    request.httpMethod = "GET"
    request.addValue("application/json", forHTTPHeaderField: "Accept")
    request.addValue("Basic amZsb3JlbmNlMEBnbWFpbC5jb206QmEka2V0YmExMUZsMEppbW15ITEh", forHTTPHeaderField: "Authorization")
    
    URLSession.shared.dataTask(with: request) { data, response, error in
        if let data = data {
            if let response = try? JSONDecoder().decode([Account].self, from: data) {
                DispatchQueue.main.async {
                    self.accounts = response
                }
                return
            }
        }
        
    }.resume()
}
}

struct AccountView_Previews: PreviewProvider {
    static var previews: some View {
        AccountView()
}
}
Back to Top