TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Project 7, Day 1 - No parsed data shown

Forums > 100 Days of Swift

@daryb  

Hello,

I've gone through the first day of Project 7 and when I build the app, it doesn't show any parsed data (title or body) in the Table View Controller. In the debug window I get the following message:

nw_protocol_get_quic_image_block_invoke dlopen libquic failed

I've also downloaded the project from the HWS Github page to make sure it wasn't something I messed up while following the tutorial, and I get the same result when trying to build; no data showing up, and same error message.

Any suggestions for next steps? Thanks!

Xcode 12.4

3      

Hi is that the White House Petitions app?

3      

@daryb  

yes, it is the white house petition one - thanks!

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Hello,

are you using the HWS url? The whitehouse.gov url is not working.

3      

@daryb  

Thanks plrichardson - yes, same outcome whether I use the cached HWS url or the real whitehouse feed.

3      

Pretty sure that error is something you can ignore. It started popping up with Xcode 12 and doesn't prevent apps from running.

Not sure why you can't get even Paul's project to work. My version of Project 7 works once I swap out the hackingwithswift.com URL for the non-functioning whitehouse.gov one. And if I download Paul's github repository and run that project, it also works after swapping out the URL.

Maybe post your ViewController.swift code so we can take a look? Although, that won't explain why you can't get Paul's project to work but it's a start.

3      

@daryb  

Thanks @roosterboy - sorry for the delay. Because Paul's project has the same result, I'm also stumped on this one. Here's my ViewController.swift code though in case that does help:

import UIKit

class ViewController: UITableViewController {

    var petitions = [Petition]()

    func parse(json: Data) {
        let decoder = JSONDecoder()

        if let jsonPetitions = try? decoder.decode(Petitions.self, from: json) {
            petitions = jsonPetitions.results
            tableView.reloadData()
        }
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return petitions.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        let petition = petitions[indexPath.row]
        cell.textLabel?.text = petition.title
        cell.detailTextLabel?.text = petition.body
        return cell
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // let urlString = "https://api.whitehouse.gov/v1/petitions.json?limit=100"
        let urlString = "https://www.hackingwithswift.com/samples/petitions-1.json"

        if let url = URL(string: urlString) {
            if let data = try? Data(contentsOf: url) {
                parse(json: data)
            }
        }
    }
}

3      

Interesting...

If I replace the ViewController in my own project with yours, it works.

All I can think is that maybe the URL is being blocked on your system somehow? What happens if try to go to the JSON's URL in a browser window?

3      

@daryb  

Thanks for checking the file - when I go to the json feed in a browser it shows up correctly. I also disabled my VPN (which has some blocking as well), just to make sure, and I'm still getting the same result. hmmm....

3      

i am having the same problem....

3      

@n35k4  

Hello guys,

I had exactly the same issue, and managed to solve it.

First, looks like the whitehouse API is not working anymore,so the following domains(or any related to the API itself) will not work : https://api.whitehouse.gov/v1/petitions.json?limit=100 and https://api.whitehouse.gov/v1/petitions.json?signatureCountFloor=10000&limit=100 So we will need to use Pauls: https://www.hackingwithswift.com/samples/petitions-1.json and https://www.hackingwithswift.com/samples/petitions-2.json

Second, the issue with no parsed data even with Pauls link was a silly typo from my side in the Petition object. I wrote var signatureCounter: Int instead of var signatureCount: Int .

This why for example when @roosterboy replaced the ViewController it started working on his end.

After fixing the typo, it all worked perfectly! So check carefully for any typos!!! Good luck guys and girls !

// This is the proper one
struct Petition: Codable {
    var title: String
    var body: String
    var signatureCount: Int
}

3      

Yet another example of why one should not decode JSON like this:

        if let jsonPetitions = try? decoder.decode(Petitions.self, from: json) {
            petitions = jsonPetitions.results
            tableView.reloadData()
        }

but should instead use a do {} catch {} block to handle any errors. That try? just swallows any errors and leaves one wondering what the heck is wrong. But if a do {} catch {} had been used instead:

        do {
            let jsonPetitions = try decoder.decode(Petitions.self, from: json)
            petitions = jsonPetitions.results
            tableView.reloadData()
        } catch {
            print(error) //handle it better in a real app
        }

there would have been a keyNotFound error for the signatureCounter property and the issue would have been much clearer.

4      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.