I had to come back and watch this again. Why? Because people who watched this came to me for help. *This is a great instructional video* However, it is only one side of the same coin. The other side of the coin... doing something practical with the JSON data outside the scope of the completion handler. Maybe presenting the data in a tableView and *not* on a background thread. And having that data available when a user selects a tableViewCell. So many people have come to me because they do not know how to continue where this video leaves off. People are looking forward to seeing Part 2 of this. Thank you.
CodeWithChris - Thank you Francis. However, that specific video mostly describes what an API is. Great for anyone wanting only to know what an API is. Unfortunately, that video *is not* the equivalent to a Part 2 of this video. This video needs a genuine follow up to show how to retain and use the collected JSON data *outside the scope of the completion handler* Getting the data is half the objective, processing and presenting it, is the remaining half. How many apps in the App Store use print(“...”) to display data to the user? Hint: the answer rhymes with Nero. A genuine Part 2 to this video, would be welcomed by many people.
I am literally watching this video while on a bus, heading to the company that contracted me to update their app and implement a functionality that requires exactly what's explained here. Talk about winging it lmao. Thanks Chris 👍
I had to parse JSON a couple of Swift versions ago and it was such a PAIN to parse JSON back then, so happy that the Apple developers improved this, so much easier nowadays 👍
Hello Chris, thank you for this video. I am no non programmer and this video helped to explain what JSON is so at least I can understand what my dev team says.
Happy to help, thanks for being a supporter for 7 months+ too! PS: We are working and planning on so much good stuff for the rest of the year! Uuuuuuuuuh @AdrienVillez
you are great man! really great. Because you make your videos touching all required points, topics, subjects while developing the target code, not just copy pasting the code.
Hi, kindly post your question in our CodeCrew forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
Hey Chris thanks a lot for making these great videos, you teach stuff very well and also you say some valuable experience while you teaching such as put some breakpoint or use debug console and also make properties optional. Thanks a lot again
Hi Christ. It is good and easier to understand parsing Jason to Swift not swiftUI, I am glad to to understand the basic. How to creat a json file Menu I'd, name, cost, description as you API.. Thanks
I can't post a link here because RUclips is gonna flag my comment, but Google "email validation Swift Github" and you'll find some pretty great things!
Great video, very insightful thank you! Is there anyway , you could do a series on this to go into more detail? I get the general gist but not sure I would be able to replicate on my own. A tutorial in the context of an app that displays the parsed information would be very helpful. Also have you mentioned things like "do catch try" in other videos? This was my first time hearing it and was a bit confusing.
Great content Chris and co!! Would love to see a Facebook API in action. Looking to grab a pages info to keep up to date on that companies events (gatherings) in my application.
Very Nice. I was very frustrated first time I tried to use this API in a headlines app tutorial as several of the data values would come up nil. This explanation and data modeling was much clearer to me. Thank You. Im using Xcode 11.3.1 and don't get the nice human readable JSON format in the terminal at the print(newsFeed) statement. Also I get an error at that breakpoint when trying to 'po newsFeed' ; that I'm assuming is related to my older Xcode. Thanks Again. I learn something new with each of your video postings.
Hello, kindly post your question on our CodeCrew forum so that our tech support can give you insights about this. Go here: codecrew.codewithchris.com. Thank you! -Arthur
How would you go about parsing date ranges? For example, the data goes back to 1914, but I only want to extract data from 2020. What woud be the best way to do it? example- To filter the dataset to only return records containing a specified value for incident_datetime simply add a URL parameter to your URL with incident_datetime as the key and your specified value.
Hello, as long as the records are in the same format then it then be fine, you might need to ""recalculate"" or cast your date records into Date format so it will be easier to handle, i suggest searching around on google there are plenty of articles that cover ordering/filtering by date - Francis
Nice video. The Facebook API would be nice. Thanks. 👍🏻😀 I have to admit, I have my own selfish motivation for that suggestion. Lol. There are billions of active FB users who use the wealth of features and services offered by FB. However, there is a glaring omission in the world of FB. It is a feature I have wanted for years... I cannot be the only one who wants it. Lol. Oh yeah... FB no longer supports their own Objective-C SDK. Thank you FB. Now I have to venture into Swift. I almost forgot... the feature I want to implement, uses a new dynamic approach to security by retrieving bare minimal information... only when it is needed. The code I have in mind will *NOT enumerate* through all friends and collect their info. *Bare minimum info only when needed.* I want to make and sell an app that works as advertised, not take advantage of people after they buy the app.
"Hello, usually that would be considered as an API interaction, or maybe database.. most of the time the data is sent as JSON but you update by batch using the API - Francis"
Hi, I know this is quite late, from when this video came out, but I was wondering where do we put the session request and everything. Chris said that we shouldn't put it in the viewcontroller. Where do we put it?
Hello, i suggest putting the request in ViewWillAppear(), or a button (or asyncronous function) that will have a chance to trigger a "refresh" in your collection. and will thus update data - Francis
Hello, there shouldn't be too much difference in codes when parsing the json, the main difference would be how to create the user interface, for now the storyboard is still the one prominently used because swiftui can only be used by ios 13 and above - Francis
After watching the video (numerous times) I built an Xcode project to mimic what you did in the video. I got it all working and then made a change were retrieving the JSON feed is being handled in a method within ViewController.swift. So now the only additional line in the viewDidLoad() method is this: getJSONFeed(). The method (getJSONFeed) is working fine and I'm able to put in a break and make sure that I did, indeed, retrieve the JSON data feed but I'm having trouble trying to figure out HOW to pass that data back from the method getJSONFeed() to viewDidLoad(). I think I have two problems that I need help with: 1. I have created a class property as an optional NewsFeed type: var thisNewsFeed:NewsFeed? I'm not sure if this is correct. 2. I am then trying to set this variable within the getJSONFeed() method by adding self.thisNewsFeed = newsFeed. I then placed a print(self.thisNewsFeed) in the code and it properly displays the JSON data that was retrieved. However when trying to access the thisNewsFeed back in viewDidLoad(), after the call to getJSONFeed() it's NIL. I think my problem is this: how to pass data from a closure. here is the ViewController.swift code: import UIKit class ViewController: UIViewController { // Class properties var thisNewsFeed:NewsFeed? override func viewDidLoad() { super.viewDidLoad() getJsonFeed() // peek at value of class property after the call to getJsonFeed() if thisNewsFeed != nil { print(thisNewsFeed!) } } func getJsonFeed() { // Hit the API endpoint let urlString = "newsapi.org/v2/everything?q=bitcoin&from=2020-02-12&sortBy=publishedAt&apiKey=hiding_my_api_key_for_this_posting" let url = URL(string: urlString) let session = URLSession.shared let dataTask = session.dataTask(with: url!){ ( data, response, error) in // check for errors if error == nil && data != nil { do { // Parse JSON let decoder = JSONDecoder() let newsFeed = try decoder.decode(NewsFeed.self, from: data!) // now set the class property thisNewsFeed self.thisNewsFeed = newsFeed // and display it to insure it actually contains the JSON data print(self.thisNewsFeed!) } catch { print("error in JSON Parsing") } } } // Make the API Call dataTask.resume() } } Any help would be appreciated!!!
I just tried to run this and I'm getting an error because the site is not secure. Says "App Transport Security has blocked a cleartext HTTP () resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." I have no idea how to tweak the Info.plist file to accommodate this. Can anyone help?
Hello, you can try to add an "allows arbitrary loads" in your info.plist, or you can simply try to load your resource using "https" instead of just "http" apple is pretty strict about this - Francis
Hey guys, everything in this code works except the very last line. I get this error code in regards to the follopwing. Are there any suggestions? error- "Variable used within its own initial value" This is the line of code that recieves the error "dataTask.resume() "
Hello, check your ""resume()"" function, it seems that you might be settting a constant value to itself(or same named parameter) so change the parameter name to avoid the error - Francis
A few people have asked this perhaps you know what to do? The problem is: THEN what? I have data in a URLSession response but that's asynchronous, so my app has moved on and my data is sitting somewhere I can't access. I have a bunch of data but how do I get it back to the parent? (In Javascript I'd nest the function or use await, for example.)
Hello, you can try to make an external swift file, lets say ""globalData.swift"" and declare the variables you want to use there, you can then set the values of the variables and you will be able to access those anyway in your app - Francis
Thank you Chris... Your videos are really amazing... Please make a video on NMSSH or other framework that supports SSH remote connection... Any links to such libraries or tutorial would be highly appreciated :-)
Hi, thank you very much what a great Video.. I have a question : how to declare a dictionary in the Newsfeed.swift File, I'm trying but its not working with me ! please help me
Hey Chris! What do I do if I am working with a api that has a dictionary inside a dictionary, inside an array, etc. I know we can use the structure code, but how do we do this if it is all nested?
Hello, depends on your structure, so if you have an array inside an array its somthing like a[0][0].. or if theres a dictionary inside the array then maybe a[0]["name"], or something similar, it depends on which one is first and you just add the additional step to be able to access it - Francis
Hello, depends on you, usually after parsing you just print/present the data to the UI, or maybe do some computations with it, its all up to what your app needs - Francis
@@CodeWithChris Hey Francis, how exactly can we work with the data, such as making a list of the news articles like the ios news app? Do you have any blog posts or videos on that?
Hey Roland, right now, it doesn't remove ads but this is a good suggestion for the RUclips membership.. i might upload the RUclips videos on my course platform and make it available ad free for people in the YT membership.
Hey, The JSON parsing in my project works perfectly fine, but i have problems passing the data to my View in SwiftUI. I tried to use an observableobject, but I‘ve got problems with the initialisation. Because my variable of the type NewsFeed object has no data in it when declared.
Hello, maybe there was a mismatch somewhere that made your NewsFeed object null, you can try going to our forum at codecrew.codewithchris.com so we can take a better look at your problem - Francis
I'm working with a JSON that just gives me number as headings. I can't create constants or variables as numbers in swift so what would the solution be? It's just a practice project, I've managed to get other APIs working, but I've come across a few like that, so I'm hoping for an easy solution Thanks
Hello, it should be possible to use number as headings, may i suggest to use swiftyjson to parse your data? we have an article for it here codewithchris.com/swiftyjson/ - Francis
Chris, I was able to complete the project in this video successfully, but i get. nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused] when I hit a localhost api that returns a json result. Is there something special about making a request of a localhost as opposed to the news site in your video? I realize this is a super specific question, but I've exhausted my other resources. Very new to this...
Hello, maybe you might need a special permission to be able to access localhost, or your localhost itself is not configured properly to accept connections. check the permissions along with your localhost to see the problem - Francis
Hi Francis! Hi Chris! It would be great if you could make a tutorial explaining how to display JSON data in SwiftUI. There's already several tutorials out there explaining this but they all use the List container to display the data. But Lists require your struct to be Identifiable, otherwise it won't work: ``` struct Todo: Codable, Identifiable { public var id: Int public var title: String public var completed: Bool } ``` In this example the response object from the API has and "id" key. But what if it didn't have one? Then you cannot make it Identifiable, and therefore you cannot pass the data to a List container. Therefore, my question is: how do you display JSON data in Content View without using the List container? Thank you!
Hello, maybe using swiftyJSON is the right tool for you. check out our article about it codewithchris.com/swiftyjson/. the usage should be similar even when on SwiftUI - Francis
. I'm trying to build an app that searches through the web (Using web scraping) and returns the specified data instantly (data can be updated on the website and I want it to be updated in my app as well), can that be done with JSON?
Hello, yes usually JSON is the best way to share data between apps/websites/and a server check out our swiftyjson to handle json data codewithchris.com/swiftyjson/ - Francis
Hello, kindly post your question in our CodeCrew forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thank you! -Arthur
Stupid question, but what do we do if the json starts out as an array? For instance the reddit api for comments begins with something like 1.data.children[0].replies.body I understand how to decode everything but the array (or dictionary?) in the beginning... I try decoding it as [ObjectThatContainsData] and that doesn't work either. On stack I've seen people mention ways to work with this using serialization, but as far as I know it's always better to use decoding right?
Hello, kindly post your question in our CodeCrew forum so that our technical support staff there can assist you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
@@CodeWithChris my question was if you have any tuts or paid courses that goes in details on UI testing, and Unit testing for UIKit ? It's so hard scavenging the web for these two topics, not enough in-depth resources. If you have any resource that can help a beginner get competent in unit or UI testing please share it with me
Hi Chris! When printing the newsFeed it just says newsFeed() in the console. Do you know what the problem could be and why it doesnt print the contents of stockData?
"Hello, i think you printed the class instead, maybe it was decoded wrong,, try checking your variables it needs to be exactly the same (uppercase and lowercase) - Francis"
can you show how to implement basic user/password authentication against an API? I got an API that does not require an API key but the credentials of my user on the platform
Hello, most apps probably also has user and password functions but it may also return an API key that you can use instead for fast log-in, think of it as a UserID (primary key) of some sorts. i think its as simple as using network connections if its an API you can try our alamofire tutorial maybe it can help codewithchris.com/alamofire/ check out swiftyjson as well codewithchris.com/swiftyjson/ - Francis
Hi Chris... Good Evening. This is Pradeep from India. Honestly, I have acquired most of my Swift knowledge from your tutorials. This Video is excellent and has given a lot of insights on how to use URLSession and Codable Protocol to fetch the data and parse it. Thanks a lot. On the same note, Can you suggest on what is the best way to have a Network Manager that does this job? I don't want to write the same code in every controller and want a single place where i can fetch and parse my data that returns back to my controller? Can you please point me to any of your videos that does this?
Hello, maybe you can use the full stack notes app ruclips.net/p/PLMRqhzcHGw1YSKIO61XncxTPoFu81K1Mx or CoreData tutorial ruclips.net/p/PLMRqhzcHGw1aDYKmCuqXQ_IqpWpJlpoJ3 - Francis
Hello, maybe save the attributes on a different "column", so for a blogpost you have the "text/body", and the "style" which is the values for the NSAttributes - Francis
Hi Chris! Fantastic video, very clear and I managed to adapt it to my OpenWeather API I'm using. Is there any chance you're doing a follow up video about how to use this data to change labels and text inside of storyboard? Aim for me is to make a basic weather app as a project, but having serious trouble as to how to use this data. Thanks again for the video!
Hello, maybe you can check out our SwiftyJSON so you can see how easy it is to use the data you have read from the apis codewithchris.com/swiftyjson/ - Francis
Hi Kin! We are limited in the comment section to talk code and share screenshots, please jump over to our CodeCrew Support Group: bit.ly/CodeCrewCommunity so we can help you the best as we can! - Kat
Hi Chris, first of all thanks for the videos bru!, second, i'm what are the skills needed as a junior developer to have? i mean i would like to apply for a job but aint sure about if i got enough projects and if they are big enough
I wrote an app that stores JSON data into UserDefaults. I wanted to add a new property to the struct. When I ran the app, the decode failed. I assume it was because I attempted to read a property that wasn't defined in the JSON. Is there an easy way to get around this? Is there a specific error code I can check for?
"Hello, i don't think you can store JSON property in UserDefaults, you can probably save it as converted value (the class you made) instead, or save a local copy of the JSON file to your directory instead - Francis"
hello chris i got this error "nw_protocol_get_quic_image_block_invoke dlopen libquic failed" and the parsing got thrown . Do you know any solution? im on xcode 12.4
@@CodeWithChris What I meant was that "data!" should be replaced as guard let validata = data else { fatalError () } even without any teaching / support staff help !
"Hello, i don't think its possible to directly exact the data from a ZIP file, you will need to have the data (extracted) in the proper directory so the app can access it if you are also interested in utilizing JSON try out our swiftyJSON tutorial maybe it can help codewithchris.com/swiftyjson/ - Francis"
Great tutorial, really enjoying it... however I am getting this error... i can see many people on forums getting this error after upgrading to Xcode 12, im not sure if that is the reason, yet this is the error I am getting after running your example, what does this mean? JSON[30212:2685228] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed Error in JSON parsing
"Hello, try changing your simulator i think some people find that it works by doing this.. or ifs really the JSON thats the problem when try checking your spelling it needs to be exactly the same (includding capitalization) when you parse JSON - Francis"
Great Video, you below part of xcode seems different from mine, how did you get to get lldb po ? why didnt print happen automatically since you had print newsfeed already in the code ?
"Hello, ""lldb po"" is just a header that signifies that the data you see is coming from the debug log, so its not from the normal print log - Francis"
"Hello, yes its totally fine to have a local JSON file just set the URL to be a file with path so it gets it from the local files You can also check out our SwiftyJSON tutorial codewithchris.com/swiftyjson/ - Francis"
Wonderful video! But I keep getting this error: "typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary but found an array instead.", underlyingError: nil))" and i'm not sure what to do. If you had any advice that'd be awesome, thank you.
Hello, it seems you used an array which is not a "key-value" pair. you can check out this video for reference ruclips.net/video/mJwmGpdZQAg/видео.html - Francis
Hello, I'm not really sure what you mean, i suggest posting your error on our forum at codecrew.codewithchris.com so we can take a better look at your problem - Francis
Nice video. You said usually it is not hard coded like let urlString = ".......". Will you be making a video about the other way? I tried to use an api from rapidapi.com/ , but I could not find a json example there to create a struct base on that. Can you maybe use an api from there for next lesson and show how to do that? Thank you!
Hello, we used newsAPI for this lesson. you just need to look for documentation on rapidAPI on how they make their JSON data and how to call it - Francis
Hello, you might need to write to the file (make sure to add permissions) and you can either overwrite the entire file (to edit it), or append if you just want to add records - Francis
Parsing in the view controller at work and take off on the same day. 100213031291390231092329 video how to parse. 0 video how to do it in a separate layer
Hello, im not sure if i quite understand your question. i suggest moving to codecrew.codewithchris.com so we can take a better look at your problem and also have the opinions of other developers in the forum - Francis
@@CodeWithChris ,I don't know much English (. I mean, parsing in a view controller is a bad practice. You need to do this in a separate “net-woking” class, but no one tells how to do it
"Hello, this project is just for conceptualization and to explain how to handle JSON, for most of our newer and other projects it will be available to access in our GitHub page so you should check them out there instead - Francis"
@@CodeWithChris kk thx. Sorry, I was a little upset because I get really easily distracted and my speakers were acting weird for some reason -so it was nearly impossible to follow and I just wanted a quick copy/paste 😂
Can you please do a tutorial of using an API from one of those scooter/bike companies and displaying it on a map as I can't figure out how to implement it. Here's the GitHub page for the API I'm trying the intergrate: github.com/ubahnverleih/WoBike/blob/master/Lime.md Thanks!
I had to come back and watch this again. Why? Because people who watched this came to me for help.
*This is a great instructional video* However, it is only one side of the same coin.
The other side of the coin... doing something practical with the JSON data outside the scope of the completion handler. Maybe presenting the data in a tableView and *not* on a background thread. And having that data available when a user selects a tableViewCell.
So many people have come to me because they do not know how to continue where this video leaves off.
People are looking forward to seeing Part 2 of this. Thank you.
Hello, maybe this other video will help on how to present JSON data ruclips.net/video/Yzx7ihtCGBs/видео.html
- Francis
CodeWithChris - Thank you Francis. However, that specific video mostly describes what an API is. Great for anyone wanting only to know what an API is.
Unfortunately, that video *is not* the equivalent to a Part 2 of this video. This video needs a genuine follow up to show how to retain and use the collected JSON data *outside the scope of the completion handler* Getting the data is half the objective, processing and presenting it, is the remaining half. How many apps in the App Store use print(“...”) to display data to the user? Hint: the answer rhymes with Nero.
A genuine Part 2 to this video, would be welcomed by many people.
That‘s exactly what I would need
I am literally watching this video while on a bus, heading to the company that contracted me to update their app and implement a functionality that requires exactly what's explained here. Talk about winging it lmao. Thanks Chris 👍
Wow, what a coincidence! - Pat
I had to parse JSON a couple of Swift versions ago and it was such a PAIN to parse JSON back then, so happy that the Apple developers improved this, so much easier nowadays 👍
True! 😊
-Kat
Thank you chris I am learning lot from your tutorials. ❤️Love from India🇮🇳
Namaste! Much love to you as well! Keep on going! -Arthur
Hello Chris, thank you for this video. I am no non programmer and this video helped to explain what JSON is so at least I can understand what my dev team says.
This comment made our day. Keep on going! :) -Arthur
Wow, that was really quick! Definitely better than dealing with JSONSerialization.
Spasiba! Thanks for learning with us! -Arthur
Thank you Chris ! It helped me in learning.
You're so welcome! Have fun watching more of our tutorials!
- Kat
InstaBlaster.
Thank you so much, Chris! This tutorial was very well-paced and gave me the proper context of what was happening. Excited to see what you make next!
Happy to help, thanks for being a supporter for 7 months+ too!
PS: We are working and planning on so much good stuff for the rest of the year! Uuuuuuuuuh
@AdrienVillez
you are great man! really great. Because you make your videos touching all required points, topics, subjects while developing the target code, not just copy pasting the code.
Thank you so, so much for your kindness! We appreciate you! Gives us more motivation to keep on hustling. All the best to your projects! -Arthur
I could sure use your help setting up this dispatch API.
Hi, kindly post your question in our CodeCrew forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
Hey Chris thanks a lot for making these great videos, you teach stuff very well and also you say some valuable experience while you teaching such as put some breakpoint or use debug console and also make properties optional. Thanks a lot again
Thanks for the feedback! We really appreciate this. 😊
-Kat
Reddit API or RUclips API. Great tutorial!
Thanks! They're on our list!
- Kat
Excellent video ... thanks for sharing this ... learning a lot
Great to hear! Thanks for watching this.
- Kat
A Shopify API would be amazing. Maybe a way to fetch products or something like that
Added it to the list, thanks for suggesting!
-Kat
I know I'm late, but would love to see a demo of google earth and/or maps API!
Hello, Benjamin, can you kindly post your suggestion here: app.productstash.io/codewithchris#/ideas Thanks for learning with us! -Arthur
Spotify API would be amazing. Better yet, parsing the data and showing it in the front end
Cheers, thanks for suggesting that! :-) -Arthur
Hi Christ.
It is good and easier to understand parsing Jason to Swift not swiftUI,
I am glad to to understand the basic.
How to creat a json file
Menu
I'd, name, cost, description
as you API..
Thanks
Thank you! 🙌
- Kat
Good tutorial Chris, we will wait for SwiftUi as the same... your solution. Thank you
Cheers, Andrej! Glad to know that you are happily learning with us. :-) -Arthur
Very nice. I would like to see an email validator API
I can't post a link here because RUclips is gonna flag my comment, but Google "email validation Swift Github" and you'll find some pretty great things!
Adrien Villez thanks 👍🏻
Thanks. 👀👍
-Kat
Thanks Chris! You are a great instructor!
And you are a great student, Dave! Appreciate you! -Arthur
you are a wonderful specimen
Haha, thanks for learning with us! -Arthur
Great video, very insightful thank you! Is there anyway , you could do a series on this to go into more detail? I get the general gist but not sure I would be able to replicate on my own. A tutorial in the context of an app that displays the parsed information would be very helpful. Also have you mentioned things like "do catch try" in other videos? This was my first time hearing it and was a bit confusing.
Hello, maybe this blog we made can help you better understand error catching codewithchris.com/swift-try-catch/
- Francis
Great content Chris and co!! Would love to see a Facebook API in action. Looking to grab a pages info to keep up to date on that companies events (gatherings) in my application.
Sounds good! It's on our list. :)
- Kat
Very Nice. I was very frustrated first time I tried to use this API in a headlines app tutorial as several of the data values would come up nil. This explanation and data modeling was much clearer to me. Thank You. Im using Xcode 11.3.1 and don't get the nice human readable JSON format in the terminal at the print(newsFeed) statement. Also I get an error at that breakpoint when trying to 'po newsFeed' ; that I'm assuming is related to my older Xcode. Thanks Again. I learn something new with each of your video postings.
Thanks for watching it! Glad to know you're learning with our tutorials.
-Kat
I always love and follow your tutorials ;what is the best networking for a beginner to learn as an iOS dev ???? thanks for this video.
Hello, kindly post your question on our CodeCrew forum so that our tech support can give you insights about this. Go here: codecrew.codewithchris.com. Thank you! -Arthur
How would you go about parsing date ranges? For example, the data goes back to 1914, but I only want to extract data from 2020. What woud be the best way to do it?
example-
To filter the dataset to only return records containing a specified value for incident_datetime simply add a URL parameter to your URL with incident_datetime as the key and your specified value.
Hello, as long as the records are in the same format then it then be fine, you might need to ""recalculate"" or cast your date records into Date format so it will be easier to handle, i suggest searching around on google there are plenty of articles that cover ordering/filtering by date
- Francis
Nice tutorial. Thanks!
Thank you! 🙌
-Kat
Nice video. The Facebook API would be nice. Thanks. 👍🏻😀
I have to admit, I have my own selfish motivation for that suggestion. Lol. There are billions of active FB users who use the wealth of features and services offered by FB. However, there is a glaring omission in the world of FB. It is a feature I have wanted for years... I cannot be the only one who wants it. Lol. Oh yeah... FB no longer supports their own Objective-C SDK. Thank you FB. Now I have to venture into Swift.
I almost forgot... the feature I want to implement, uses a new dynamic approach to security by retrieving bare minimal information... only when it is needed. The code I have in mind will *NOT enumerate* through all friends and collect their info. *Bare minimum info only when needed.* I want to make and sell an app that works as advertised, not take advantage of people after they buy the app.
I'll add the Facebook API to the list.
-Kat
CodeWithChris - Thank you. Much appreciated. 👍🏻😀
Nice video sir, keep going.
Thank you!
- Kat
@CodeWIthChris is there a way to edit the information on a JSON extracted file and feed it back to the orginator?
"Hello, usually that would be considered as an API interaction, or maybe database.. most of the time the data is sent as JSON but you update by batch using the API
- Francis"
I know it isn't the focus of the video but what is the best way to manage API keys in Xcode?
Hello, that depends maybe you can put it in UserDefaults for quick saving and access
- Francis
Hi, I know this is quite late, from when this video came out, but I was wondering where do we put the session request and everything. Chris said that we shouldn't put it in the viewcontroller. Where do we put it?
Hello, i suggest putting the request in ViewWillAppear(), or a button (or asyncronous function) that will have a chance to trigger a "refresh" in your collection. and will thus update data
- Francis
Hey how to get this news API for my practice? can you please mention it in description box.
So why are you choosing to use Swift Storyboards for this demo vs SwiftUI? Is there a difference for how this is done? Thanks!
Hello, there shouldn't be too much difference in codes when parsing the json, the main difference would be how to create the user interface, for now the storyboard is still the one prominently used because swiftui can only be used by ios 13 and above
- Francis
After watching the video (numerous times) I built an Xcode project to mimic what you did in the video. I got it all working and then made a change were retrieving the JSON feed is being handled in a method within ViewController.swift. So now the only additional line in the viewDidLoad() method is this: getJSONFeed(). The method (getJSONFeed) is working fine and I'm able to put in a break and make sure that I did, indeed, retrieve the JSON data feed but I'm having trouble trying to figure out HOW to pass that data back from the method getJSONFeed() to viewDidLoad().
I think I have two problems that I need help with:
1. I have created a class property as an optional NewsFeed type: var thisNewsFeed:NewsFeed?
I'm not sure if this is correct.
2. I am then trying to set this variable within the getJSONFeed() method by adding self.thisNewsFeed = newsFeed. I then placed a print(self.thisNewsFeed) in the code and it properly displays the JSON data that was retrieved. However when trying to access the thisNewsFeed back in viewDidLoad(), after the call to getJSONFeed() it's NIL. I think my problem is this: how to pass data from a closure.
here is the ViewController.swift code:
import UIKit
class ViewController: UIViewController {
// Class properties
var thisNewsFeed:NewsFeed?
override func viewDidLoad() {
super.viewDidLoad()
getJsonFeed()
// peek at value of class property after the call to getJsonFeed()
if thisNewsFeed != nil {
print(thisNewsFeed!)
}
}
func getJsonFeed() {
// Hit the API endpoint
let urlString = "newsapi.org/v2/everything?q=bitcoin&from=2020-02-12&sortBy=publishedAt&apiKey=hiding_my_api_key_for_this_posting"
let url = URL(string: urlString)
let session = URLSession.shared
let dataTask = session.dataTask(with: url!){ ( data, response, error) in
// check for errors
if error == nil && data != nil {
do {
// Parse JSON
let decoder = JSONDecoder()
let newsFeed = try decoder.decode(NewsFeed.self, from: data!)
// now set the class property thisNewsFeed
self.thisNewsFeed = newsFeed
// and display it to insure it actually contains the JSON data
print(self.thisNewsFeed!)
}
catch {
print("error in JSON Parsing")
}
}
}
// Make the API Call
dataTask.resume()
}
}
Any help would be appreciated!!!
Hello, i suggest moving this problem to our public forum at codecrew.codewithchris.com so we can take a better look at your project
- Francis
Great video. Thanks!
Thanks for watching it!
-Kat
I just tried to run this and I'm getting an error because the site is not secure. Says "App Transport Security has blocked a cleartext HTTP () resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." I have no idea how to tweak the Info.plist file to accommodate this. Can anyone help?
Hello, you can try to add an "allows arbitrary loads" in your info.plist, or you can simply try to load your resource using "https" instead of just "http" apple is pretty strict about this
- Francis
Hey guys, everything in this code works except the very last line. I get this error code in regards to the follopwing. Are there any suggestions?
error- "Variable used within its own initial value"
This is the line of code that recieves the error "dataTask.resume() "
Hello, check your ""resume()"" function, it seems that you might be settting a constant value to itself(or same named parameter) so change the parameter name to avoid the error
- Francis
Thank you chris !
You're so welcome! -Arthur
Please upload more videos on this, also with http header
Yes, there will be more videos like this! :)
-Kat
A few people have asked this perhaps you know what to do? The problem is: THEN what? I have data in a URLSession response but that's asynchronous, so my app has moved on and my data is sitting somewhere I can't access. I have a bunch of data but how do I get it back to the parent? (In Javascript I'd nest the function or use await, for example.)
This answered it for me. I was doing a web API call. ruclips.net/video/tdxKIPpPDAI/видео.html
Hello, you can try to make an external swift file, lets say ""globalData.swift"" and declare the variables you want to use there, you can then set the values of the variables and you will be able to access those anyway in your app
- Francis
Thank you Chris... Your videos are really amazing... Please make a video on NMSSH or other framework that supports SSH remote connection... Any links to such libraries or tutorial would be highly appreciated :-)
Thanks for the support and suggestion! :-) -Arthur
Hi, thank you very much what a great Video..
I have a question : how to declare a dictionary in the Newsfeed.swift File, I'm trying but its not working with me ! please help me
Hello, this video should help you learn about dictionaries, dont worry they will work the same
- Francis
I love this dude!
Thank you! 🙌
- Kat
Thank you! That helped!
Anytime. Thanks for learning with us! :) -Arthur
Hey Chris! What do I do if I am working with a api that has a dictionary inside a dictionary, inside an array, etc. I know we can use the structure code, but how do we do this if it is all nested?
Hello, depends on your structure, so if you have an array inside an array its somthing like a[0][0].. or if theres a dictionary inside the array then maybe a[0]["name"], or something similar, it depends on which one is first and you just add the additional step to be able to access it
- Francis
@@CodeWithChris thanks for the reply, that worked!
Thank you so much!
You're welcome! -Arthur
Now that it’s done, what do you with that after your parse it?
Hello, depends on you, usually after parsing you just print/present the data to the UI, or maybe do some computations with it, its all up to what your app needs
- Francis
@@CodeWithChris Hey Francis, how exactly can we work with the data, such as making a list of the news articles like the ios news app? Do you have any blog posts or videos on that?
This is outside of this video, but if I hit `JOIN` will I still see ads or not? And how can I see your videos without ads (without premium RUclips)?
Hey Roland, right now, it doesn't remove ads but this is a good suggestion for the RUclips membership.. i might upload the RUclips videos on my course platform and make it available ad free for people in the YT membership.
Hey, The JSON parsing in my project works perfectly fine, but i have problems passing the data to my View in SwiftUI. I tried to use an observableobject, but I‘ve got problems with the initialisation. Because my variable of the type NewsFeed object has no data in it when declared.
Hello, maybe there was a mismatch somewhere that made your NewsFeed object null, you can try going to our forum at codecrew.codewithchris.com so we can take a better look at your problem
- Francis
Love it 💚
Thank you so much! - Pat
I'm working with a JSON that just gives me number as headings. I can't create constants or variables as numbers in swift so what would the solution be? It's just a practice project, I've managed to get other APIs working, but I've come across a few like that, so I'm hoping for an easy solution
Thanks
Hello, it should be possible to use number as headings, may i suggest to use swiftyjson to parse your data? we have an article for it here codewithchris.com/swiftyjson/
- Francis
Chris, I was able to complete the project in this video successfully, but i get. nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused]
when I hit a localhost api that returns a json result. Is there something special about making a request of a localhost as opposed to the news site in your video? I realize this is a super specific question, but I've exhausted my other resources. Very new to this...
Hello, maybe you might need a special permission to be able to access localhost, or your localhost itself is not configured properly to accept connections.
check the permissions along with your localhost to see the problem
- Francis
Hi Francis! Hi Chris!
It would be great if you could make a tutorial explaining how to display JSON data in SwiftUI.
There's already several tutorials out there explaining this but they all use the List container to display the data. But Lists require your struct to be Identifiable, otherwise it won't work:
```
struct Todo: Codable, Identifiable {
public var id: Int
public var title: String
public var completed: Bool
}
```
In this example the response object from the API has and "id" key. But what if it didn't have one? Then you cannot make it Identifiable, and therefore you cannot pass the data to a List container.
Therefore, my question is: how do you display JSON data in Content View without using the List container?
Thank you!
Hello, maybe using swiftyJSON is the right tool for you. check out our article about it codewithchris.com/swiftyjson/.
the usage should be similar even when on SwiftUI
- Francis
.
I'm trying to build an app that searches through the web (Using web scraping) and returns the specified data instantly (data can be updated on the website and I want it to be updated in my app as well), can that be done with JSON?
Hello, yes usually JSON is the best way to share data between apps/websites/and a server
check out our swiftyjson to handle json data codewithchris.com/swiftyjson/
- Francis
Hey Chris, awesome video! I was wondering if you would consider parsing JSON with Text & Image into a TableView. If yes, waiting for the tutorial 🙏
Hello, kindly post your question in our CodeCrew forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thank you! -Arthur
Stupid question, but what do we do if the json starts out as an array? For instance the reddit api for comments begins with something like 1.data.children[0].replies.body
I understand how to decode everything but the array (or dictionary?) in the beginning... I try decoding it as [ObjectThatContainsData] and that doesn't work either. On stack I've seen people mention ways to work with this using serialization, but as far as I know it's always better to use decoding right?
Hello, kindly post your question in our CodeCrew forum so that our technical support staff there can assist you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
Thanks a lot Chris! This means a lot. I messaged you on Twitter haven’t heard back 😃
What is it? Hope we have already responded to it by now. If it's a technical question, post it here: codecrew.codewithchris.com. Enjoy! -Arthur
@@CodeWithChris my question was if you have any tuts or paid courses that goes in details on UI testing, and Unit testing for UIKit ? It's so hard scavenging the web for these two topics, not enough in-depth resources. If you have any resource that can help a beginner get competent in unit or UI testing please share it with me
Hi Chris! When printing the newsFeed it just says newsFeed() in the console. Do you know what the problem could be and why it doesnt print the contents of stockData?
"Hello, i think you printed the class instead, maybe it was decoded wrong,, try checking your variables it needs to be exactly the same (uppercase and lowercase)
- Francis"
can you show how to implement basic user/password authentication against an API? I got an API that does not require an API key but the credentials of my user on the platform
Hello, most apps probably also has user and password functions but it may also return an API key that you can use instead for fast log-in, think of it as a UserID (primary key) of some sorts. i think its as simple as using network connections if its an API
you can try our alamofire tutorial maybe it can help codewithchris.com/alamofire/
check out swiftyjson as well codewithchris.com/swiftyjson/
- Francis
CodeWithChris I could solve it now on my own by using the HTTP Header attribute „authorization“
I would like to see Vk API. How to transform time(duration) into readable format(00:00 or 00:00:00), representing time unit
Thanks for the suggestion! I'll add it to the list.
-Kat
CodeWithChris, I have figured out how to do that with DateComponentsFormatter.
Please make video for adding image in core data
Thanks for the suggestion! Check this out www.vadimbulavin.com/how-to-save-images-and-videos-to-core-data-efficiently/
-Kat
Hi Chris... Good Evening. This is Pradeep from India. Honestly, I have acquired most of my Swift knowledge from your tutorials. This Video is excellent and has given a lot of insights on how to use URLSession and Codable Protocol to fetch the data and parse it. Thanks a lot. On the same note, Can you suggest on what is the best way to have a Network Manager that does this job? I don't want to write the same code in every controller and want a single place where i can fetch and parse my data that returns back to my controller? Can you please point me to any of your videos that does this?
Hello, maybe you can use the full stack notes app ruclips.net/p/PLMRqhzcHGw1YSKIO61XncxTPoFu81K1Mx
or CoreData tutorial ruclips.net/p/PLMRqhzcHGw1aDYKmCuqXQ_IqpWpJlpoJ3
- Francis
@@CodeWithChris Thanks a lot.. Will check out all those 4 videos in the suggested Playlist..
Hi Chris,
If I wanted my JSON to have elements that are underlined or italicized and then save it as a NSAttributedText... how would I do that?
Hello, maybe save the attributes on a different "column", so for a blogpost you have the "text/body", and the "style" which is the values for the NSAttributes
- Francis
@@CodeWithChris Thanks. I went with an HTML parser instead.
do you have an example that shows how to create the json object with dictionary datatype.
"Hello, try checking out results from like itunes API or something it should be similar
- Francis"
Hi Chris!
Fantastic video, very clear and I managed to adapt it to my OpenWeather API I'm using.
Is there any chance you're doing a follow up video about how to use this data to change labels and text inside of storyboard?
Aim for me is to make a basic weather app as a project, but having serious trouble as to how to use this data.
Thanks again for the video!
Hello, maybe you can check out our SwiftyJSON so you can see how easy it is to use the data you have read from the apis codewithchris.com/swiftyjson/
- Francis
Okay so how would we then present that data in the storyboard? I've searched it up and I cant find how to actually use the data?!
Hello, you can use it as the source data for a tableview/colletionview for example
- Francis
Can I put struct of Article directly inside the NewsFeed.swift?
Hi Kin! We are limited in the comment section to talk code and share screenshots, please jump over to our CodeCrew Support Group: bit.ly/CodeCrewCommunity so we can help you the best as we can!
- Kat
Hi Chris, first of all thanks for the videos bru!, second, i'm what are the skills needed as a junior developer to have? i mean i would like to apply for a job but aint sure about if i got enough projects and if they are big enough
We released a video about that, watch this: ruclips.net/video/x9tv-bDQi5Q/видео.html :)
- Kat
I wrote an app that stores JSON data into UserDefaults. I wanted to add a new property to the struct. When I ran the app, the decode failed. I assume it was because I attempted to read a property that wasn't defined in the JSON. Is there an easy way to get around this? Is there a specific error code I can check for?
"Hello, i don't think you can store JSON property in UserDefaults, you can probably save it as converted value (the class you made) instead, or save a local copy of the JSON file to your directory instead
- Francis"
hello chris i got this error "nw_protocol_get_quic_image_block_invoke dlopen libquic failed" and the parsing got thrown . Do you know any solution? im on xcode 12.4
"Hello, this seems to be a common simulator issue recently, try changing to a different device
- Francis"
Hey Chris make a video on OAuth Api
It's already added on our list, don't worry! We just have a very long list of topics to cover. 😄
-Kat
Hi Chris, thank you so much, would love to see you demo shift4shop REST API mainly interested in how to retrieve a list of orders.
Thank you
HI Ibrahim! You can post tutorial recommendations here app.productstash.io/codewithchris#/ideas and we'll have our team take a look at it. :) - Pat
Great thank you .
Thanks !
Welcome! -Arthur
Can you make a video on parsing data by json serialisation
Thanks for your suggestion! :-) -Arthur
@@CodeWithChris Thanks, eagerly waiting for it....
@20:50 who teaches you to force unwrapped that "data" on line #38 ???
Hello, best if you talk to our tech support staff about this: codecrew.codewithchris.com. Thank you, James! -Arthur
@@CodeWithChris What I meant was that "data!" should be replaced as
guard let validata = data else { fatalError () }
even without any teaching / support staff help !
Sir? Is there anyvideo regarding accessing json data in a zip file and then using that data to map our UI?
"Hello, i don't think its possible to directly exact the data from a ZIP file, you will need to have the data (extracted) in the proper directory so the app can access it
if you are also interested in utilizing JSON try out our swiftyJSON tutorial maybe it can help codewithchris.com/swiftyjson/
- Francis"
@@CodeWithChris thank you very much sir, i hope your channel grows to be one of the best ❤️
Great tutorial, really enjoying it...
however I am getting this error... i can see many people on forums getting this error after upgrading to Xcode 12, im not sure if that is the reason, yet this is the error I am getting after running your example, what does this mean?
JSON[30212:2685228] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
Error in JSON parsing
"Hello, try changing your simulator i think some people find that it works by doing this.. or ifs really the JSON thats the problem when try checking your spelling it needs to be exactly the same (includding capitalization) when you parse JSON
- Francis"
I fixed it by using square brackets on newsfeed --> [newsfeed].self instead of newsfeed.self . I hope this helps
Hey Chris, I wanted to find a job as IOS developer this year and I wonder should I actually learn UIKit or not?
What you think about it?
Yes!! ALL production apps by companies will be UIKit, no one other than indies are using SwiftUI because it's brand new
Yup, Mikaela is right. If you intend to get an iOS development job, knowing how to use UIKit is still a requirement for most companies.
-Kat
Thanks
You are so welcome! -Arthur
Great Video, you below part of xcode seems different from mine, how did you get to get lldb po ? why didnt print happen automatically since you had print newsfeed already in the code ?
"Hello, ""lldb po"" is just a header that signifies that the data you see is coming from the debug log, so its not from the normal print log
- Francis"
Cool.
Thx
Thanks for watching!
-Kat
Chris: Any chance of getting a copy of this Xcode project to play around with? Thanks! (Great video by the way!!!!)
Thank you! Unfortunately, we don't have the source code available for this project.
-Kat
what about a local JSON fil thats part of your project?
"Hello, yes its totally fine to have a local JSON file just set the URL to be a file with path so it gets it from the local files
You can also check out our SwiftyJSON tutorial codewithchris.com/swiftyjson/
- Francis"
Wonderful video! But I keep getting this error: "typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary but found an array instead.", underlyingError: nil))" and i'm not sure what to do. If you had any advice that'd be awesome, thank you.
Hello, it seems you used an array which is not a "key-value" pair. you can check out this video for reference
ruclips.net/video/mJwmGpdZQAg/видео.html
- Francis
good
Thanks! 🙌
sir, i met with ATS block. what's wrong with me
Hello, I'm not really sure what you mean, i suggest posting your error on our forum at codecrew.codewithchris.com so we can take a better look at your problem
- Francis
Nice video. You said usually it is not hard coded like let urlString = ".......". Will you be making a video about the other way? I tried to use an api from rapidapi.com/ , but I could not find a json example there to create a struct base on that. Can you maybe use an api from there for next lesson and show how to do that? Thank you!
Hello, we used newsAPI for this lesson. you just need to look for documentation on rapidAPI on how they make their JSON data and how to call it
- Francis
can you make video on sunshine conversation api for facebook integration.
Thanks for your suggestion! Can you kindly post your suggestion here: app.productstash.io/codewithchris#/ideas :-) -Arthur
Hi Chris! How can I send a request or change a value in the JSON file with an action in my App?
Hello, you might need to write to the file (make sure to add permissions) and you can either overwrite the entire file (to edit it), or append if you just want to add records
- Francis
CodeWithChris Thank you so much!
dictionary inside array [{},{},{},]
You don't need the final comma, ;)
@AdrienVillez
hello sir can you make project on moya
"Hello, sadly our channel only focuses on iOS content. Thank you for showing in the channel though, much appreciated
- Francis"
Parsing in the view controller at work and take off on the same day. 100213031291390231092329 video how to parse. 0 video how to do it in a separate layer
Hello, im not sure if i quite understand your question. i suggest moving to codecrew.codewithchris.com so we can take a better look at your problem and also have the opinions of other developers in the forum
- Francis
@@CodeWithChris ,I don't know much English (. I mean, parsing in a view controller is a bad practice. You need to do this in a separate “net-woking” class, but no one tells how to do it
Would it kill you to put the code on github?
"Hello, this project is just for conceptualization and to explain how to handle JSON, for most of our newer and other projects it will be available to access in our GitHub page so you should check them out there instead
- Francis"
@@CodeWithChris kk thx. Sorry, I was a little upset because I get really easily distracted and my speakers were acting weird for some reason -so it was nearly impossible to follow and I just wanted a quick copy/paste 😂
API for iOS app please🙏
Thanks for dropping by! :) -Arthur
Can you please do a tutorial of using an API from one of those scooter/bike companies and displaying it on a map as I can't figure out how to implement it. Here's the GitHub page for the API I'm trying the intergrate: github.com/ubahnverleih/WoBike/blob/master/Lime.md Thanks!
Hello, you can send us your requests here: cwc.to/request
- Kat
Facebook API please
Hello! Thanks for the suggestion, it's in our future topics list. :)
- Kat
Great video! Thank you.
Thanks for watching! 🙌
-Kat