Saturday, November 21, 2026
HomeiOS Developmentios - Situation passing information from API name in SwiftUI MVVM sample

ios – Situation passing information from API name in SwiftUI MVVM sample

[ad_1]

been going backwards and forwards for two days attempting to determine this out earlier than posting and nonetheless hitting a wall.

Created an API particular class, a ViewModel, and a View and attempting to shuttle information backwards and forwards and whereas I see the API name is profitable and I decode it with out problem on logs, it by no means displays on the UI or View.

So far as I see I look like attempting to entry the information earlier than it is truly out there. All assist vastly appreciated!

API Class:

import Mix
import Basis

class CrunchbaseApi:ObservableObject
{
    @Printed var firms:[Company] = [Company]()
    @Printed var singleCompany:Firm?

        
    func retrieve(firm:String) async
    {
        let SingleEntityURL:URL = URL(string:"https://api.crunchbase.com/api/v4/entities/organizations/(firm)?card_ids=fields&user_key=**********REMOVED FOR SECURITY*****************")!
        
        let job = URLSession.shared.dataTask(with:SingleEntityURL){ information, response, error in

            let decoder = JSONDecoder()
            
            if let information = information{
                do {
                    self.singleCompany = strive decoder.decode(Firm.self, from: information)
                } catch  {
                    print(error.localizedDescription)
                }
            }
        }
        job.resume()
    }
    
    func retrieveCompanyList()
    {
        //declare
    }
}

ViewModel:

import Mix
import Basis

class CompanyViewModel: ObservableObject
{
    var crunchbase:CrunchbaseApi = CrunchbaseApi()
    @Printed var singleCompany:Firm?
    
    
    func retrieveCompany(firm:String) async
    {
        await self.crunchbase.retrieve(firm: firm)
        self.singleCompany = crunchbase.singleCompany
        
    }
    
}

View:

import SwiftUI

struct CompanyView: View
{
    @State var companyViewModel:CompanyViewModel = CompanyViewModel()
    
    
    var physique: some View
    {
        
        NavigationView
        {
            VStack
            {
                Textual content("Firm ID: (companyViewModel.singleCompany?.id ?? "NOTHING")")
              //  Textual content("Firm Title: (companyViewModel.companyName)")
             //   Textual content("Firm Abstract: (companyViewModel.companyDescription)")
             //   Textual content("Emblem URL: (companyViewModel.companyLogoURL)")
            }.navigationTitle("Firm")
        }
    }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments