Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

swift error: Value of type _ has no member _

how do I fix this error? xcodes-13

"This Is my code for working with api:"

struct everything: Codable{
        let topic: String
        let content: String
        let catagory: String
        let time: String
        let price: String
        let prize: String
    }    
    struct parsingss : Codable {
        let scrims: [everything]
    }
    
    @IBOutlet weak var prizeLabel: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var catagoryLabel: UILabel!
    @IBOutlet weak var ContentLabel: UILabel!
    @IBOutlet weak var TopicLabel: UILabel!
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let url = URL(string: "http://{Local-Host}/post") {
           URLSession.shared.dataTask(with: url) { data, response, error in
        if let data = data {
            let jsonDecoder = JSONDecoder()
            do {
            let parsedJSON = try jsonDecoder.decode(parsingss.self, from: data)
                
                print(parsedJSON)
                
                DispatchQueue.main.async {

                    self.TopicLabel.text = parsedJSON.topic
                    self.ContentLabel.text = parsedJSON.content
                    self.catagoryLabel.text = parsedJSON.catagory
                    self.timeLabel.text = parsedJSON.time
                    self.priceLabel.text = parsedJSON.price
                    self.prizeLabel.text = parsedJSON.prize
                    
                   }
                    }
            catch {
            print(error)
                        
                    }
                   }
               }.resume()
            }
    }
}

"error : Value of type ‘testViewController.parsingss’ has no member ‘topic’"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Reply with some codes would be better either ways. Thanks developers.

Without "trying to print in label", the result does come to the output. it is in an array: [ scrims: {
"topic": "tv",
"content": "done",
"catagory": "gg",
"time": "10pm",
"price": "Rs.100",
"prize": "Rs.1000",
"id": 1
},
{
"topic": "1",
"content": "d1",
"catagory": "g1",
"time": "10pm",
"price": "Rs.11",
"prize": "R1",
"id": 2
} ]

Thanks!

>Solution :

Try this:

class ViewController: UIViewController {
@IBOutlet weak var prizeLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var catagoryLabel: UILabel!
@IBOutlet weak var ContentLabel: UILabel!
@IBOutlet weak var TopicLabel: UILabel!


override func viewDidLoad() {
    super.viewDidLoad()
    
    if let url = URL(string: "http://{Local-Host}/post") {
        URLSession.shared.dataTask(with: url) { data, response, error in
            if let data = data {
                do {
                    let parsedJSON = try JSONDecoder().decode(parsingss.self, from: data)
                    
                    print(parsedJSON)
                    
                    DispatchQueue.main.async {
                        self.TopicLabel.text = parsedJSON.scrims[0].topic
                        self.ContentLabel.text = parsedJSON.scrims[0].content
                        self.catagoryLabel.text = parsedJSON.scrims[0].catagory
                        self.timeLabel.text = parsedJSON.scrims[0].time
                        self.priceLabel.text = parsedJSON.scrims[0].price
                        self.prizeLabel.text = parsedJSON.scrims[0].prize
                    }
                }
                catch {
                    print(error)
                    
                }
            }
        }.resume()
    }
}

}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading