Тёмный

What is JSON - JSON Parsing in Swift 

CodeWithChris
Подписаться 592 тыс.
Просмотров 73 тыс.
50% 1

What is JSON and how do you parse JSON in Swift? This video will show you!
JSON stands for JavaScript Object Notation and it's a way to represent data in a standard way. It helps organize that data in a way that machines can "read".
Think about how a dictionary is organized alphabetically and each entry has a word followed by a definition. There's a well defined standard which makes it easy to process the info.
The JSON data format is often used in a data feed or in the returned data from an API call.
Because the data is in a standard data format, our app can "parse" out the information from the data feed or API response.
To understand how JSON is organizes data, you need these 3 concepts:
Key-Value pairs: The key is a label and the value is the actual data. Together, a key-value pair represents one piece of information.
JSON Object: This is a collection of key-value pairs together. Often the key-value pairs are related together so that the collection (JSON object) represents a bigger piece of data. For example, the JSON Object could represent a person and the collection of key-value pairs represents the attributes of the person.
Array: An array in JSON represents a list of JSON objects or other values.
For an example of JSON data, check out the video tutorial! In the video, I also show how to parse JSON in Swift using the Codable protocol.
We take the response JSON data from a real API call and then parse it in Swift!
🚨 SPECIAL CWC+ OFFER FOR RU-vid:
cwc.to/youtubeoffer
MY FREE ONLINE COURSE:
⚡ How to make an app in 14 days - cwc.to/14days
CWC+ PROGRAM:
👩‍💻 All our courses in a learning path - cwc.to/plus
WEEKLY UPDATES VIA EMAIL:
✉️ Every Saturday, receive an email digest of new content - cwc.to/newsletter
CONNECT:
🌍 Website - codewithchris.com
😺 GitHub - github.com/codewithchris
📸 Instagram - / codewithchris
🐦 Twitter - / codewithchris
ABOUT CODEWITHCHRIS:
Hi I’m Chris! I’m dedicated to teaching fundamentals about how to make an app. This is important if you’re trying to land an iOS job, be a freelancer, increase or start a business with an app idea. On this channel and my website, you'll find a ton of free resources and tutorials to aid you on your journey to learn iOS development. Many people have learned to code and build apps on their own! cwc.to/reviews
#JSON #Parsing #CodeWithChris

Опубликовано:

 

28 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 224   
@superintegrated9994
@superintegrated9994 3 года назад
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.
@CodeWithChris
@CodeWithChris 3 года назад
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
@gauntletwielder6306
@gauntletwielder6306 4 года назад
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
@CodeWithChris 4 года назад
Hello, maybe this other video will help on how to present JSON data ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Yzx7ihtCGBs.html - Francis
@gauntletwielder6306
@gauntletwielder6306 4 года назад
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.
@toqix6861
@toqix6861 4 года назад
That‘s exactly what I would need
@MediArgentum
@MediArgentum Год назад
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 👍
@CodeWithChris
@CodeWithChris Год назад
Wow, what a coincidence! - Pat
@Viral_Meme3499
@Viral_Meme3499 3 года назад
Thank you chris I am learning lot from your tutorials. ❤️Love from India🇮🇳
@CodeWithChris
@CodeWithChris 3 года назад
Namaste! Much love to you as well! Keep on going! -Arthur
@alifarhadi5704
@alifarhadi5704 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for the feedback! We really appreciate this. 😊 -Kat
@spearlightknight1714
@spearlightknight1714 2 года назад
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.
@CodeWithChris
@CodeWithChris 2 года назад
This comment made our day. Keep on going! :) -Arthur
@pistonsky
@pistonsky 2 года назад
Wow, that was really quick! Definitely better than dealing with JSONSerialization.
@CodeWithChris
@CodeWithChris 2 года назад
Spasiba! Thanks for learning with us! -Arthur
@davetisdale8628
@davetisdale8628 3 года назад
Thanks Chris! You are a great instructor!
@CodeWithChris
@CodeWithChris 3 года назад
And you are a great student, Dave! Appreciate you! -Arthur
@Jeppelelle
@Jeppelelle 4 года назад
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 👍
@CodeWithChris
@CodeWithChris 4 года назад
True! 😊 -Kat
@rohitoznikam3735
@rohitoznikam3735 4 года назад
Thank you Chris ! It helped me in learning.
@CodeWithChris
@CodeWithChris 4 года назад
You're so welcome! Have fun watching more of our tutorials! - Kat
@daviontrevor4101
@daviontrevor4101 2 года назад
InstaBlaster.
@guruitcompany
@guruitcompany 4 года назад
Great video! Thank you.
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for watching! 🙌 -Kat
@glennadams7047
@glennadams7047 4 года назад
Nice tutorial. Thanks!
@CodeWithChris
@CodeWithChris 4 года назад
Thank you! 🙌 -Kat
@sujitmolleti2322
@sujitmolleti2322 4 года назад
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!
@CodeWithChris
@CodeWithChris 4 года назад
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
@se7enzz258
@se7enzz258 4 года назад
Great video. Thanks!
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for watching it! -Kat
@astonmartin3309
@astonmartin3309 2 года назад
Thank you! That helped!
@CodeWithChris
@CodeWithChris 2 года назад
Anytime. Thanks for learning with us! :) -Arthur
@charlesokehie6940
@charlesokehie6940 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
Hello, maybe this blog we made can help you better understand error catching codewithchris.com/swift-try-catch/ - Francis
@richardwalters9249
@richardwalters9249 3 года назад
Excellent video ... thanks for sharing this ... learning a lot
@CodeWithChris
@CodeWithChris 3 года назад
Great to hear! Thanks for watching this. - Kat
@easthastings6919
@easthastings6919 2 года назад
you are a wonderful specimen
@CodeWithChris
@CodeWithChris 2 года назад
Haha, thanks for learning with us! -Arthur
@AtesotFlavor
@AtesotFlavor 2 года назад
I could sure use your help setting up this dispatch API.
@CodeWithChris
@CodeWithChris 2 года назад
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
@NuWhite
@NuWhite 3 года назад
Thank you so much!
@CodeWithChris
@CodeWithChris 3 года назад
You're welcome! -Arthur
@adammarez2684
@adammarez2684 4 года назад
I love this dude!
@CodeWithChris
@CodeWithChris 4 года назад
Thank you! 🙌 - Kat
@TheDba6060
@TheDba6060 3 года назад
Thank you chris !
@CodeWithChris
@CodeWithChris 3 года назад
You're so welcome! -Arthur
@toqix6861
@toqix6861 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
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
@EngineeringWithEugene
@EngineeringWithEugene 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
Sounds good! It's on our list. :) - Kat
@JusCJay
@JusCJay 4 года назад
Reddit API or RU-vid API. Great tutorial!
@CodeWithChris
@CodeWithChris 4 года назад
Thanks! They're on our list! - Kat
@DrMemory99
@DrMemory99 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for watching it! Glad to know you're learning with our tutorials. -Kat
@zachariahball6464
@zachariahball6464 3 года назад
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!
@CodeWithChris
@CodeWithChris 3 года назад
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
@andrejkling3886
@andrejkling3886 3 года назад
Good tutorial Chris, we will wait for SwiftUi as the same... your solution. Thank you
@CodeWithChris
@CodeWithChris 3 года назад
Cheers, Andrej! Glad to know that you are happily learning with us. :-) -Arthur
@Ipadstands
@Ipadstands 2 года назад
Thanks !
@CodeWithChris
@CodeWithChris 2 года назад
Welcome! -Arthur
@the_meaning_of_love
@the_meaning_of_love Год назад
Love it 💚
@CodeWithChris
@CodeWithChris Год назад
Thank you so much! - Pat
@aviadsabag8193
@aviadsabag8193 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
We released a video about that, watch this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-x9tv-bDQi5Q.html :) - Kat
@shd2236
@shd2236 4 года назад
A Shopify API would be amazing. Maybe a way to fetch products or something like that
@CodeWithChris
@CodeWithChris 4 года назад
Added it to the list, thanks for suggesting! -Kat
@tharlinhtet97
@tharlinhtet97 3 года назад
Nice video sir, keep going.
@CodeWithChris
@CodeWithChris 3 года назад
Thank you! - Kat
@michaelangelos5117
@michaelangelos5117 4 года назад
Cool. Thx
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for watching! -Kat
@oshinvats7304
@oshinvats7304 4 года назад
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?
@CodeWithChris
@CodeWithChris 4 года назад
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
@avneetsingh2010
@avneetsingh2010 3 года назад
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 :-)
@CodeWithChris
@CodeWithChris 3 года назад
Thanks for the support and suggestion! :-) -Arthur
@jeffrosengarden6935
@jeffrosengarden6935 4 года назад
Chris: Any chance of getting a copy of this Xcode project to play around with? Thanks! (Great video by the way!!!!)
@CodeWithChris
@CodeWithChris 4 года назад
Thank you! Unfortunately, we don't have the source code available for this project. -Kat
@TylerWasick
@TylerWasick 4 года назад
So why are you choosing to use Swift Storyboards for this demo vs SwiftUI? Is there a difference for how this is done? Thanks!
@CodeWithChris
@CodeWithChris 4 года назад
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
@mookastudio
@mookastudio 2 года назад
Thanks
@CodeWithChris
@CodeWithChris 2 года назад
You are so welcome! -Arthur
@michaelpowers7164
@michaelpowers7164 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
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
@jovictor3007
@jovictor3007 3 года назад
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 ?
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@SauravKumar-si6yg
@SauravKumar-si6yg 4 года назад
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?
@CodeWithChris
@CodeWithChris 4 года назад
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
@SauravKumar-si6yg
@SauravKumar-si6yg 4 года назад
@@CodeWithChris thanks for the reply, that worked!
@withd5943
@withd5943 2 года назад
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 🙏
@CodeWithChris
@CodeWithChris 2 года назад
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
@michaelpowers7164
@michaelpowers7164 4 года назад
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() "
@CodeWithChris
@CodeWithChris 4 года назад
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
@natgenesis5038
@natgenesis5038 2 года назад
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.
@CodeWithChris
@CodeWithChris 2 года назад
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
@ishowyouapple
@ishowyouapple 4 года назад
Now that it’s done, what do you with that after your parse it?
@CodeWithChris
@CodeWithChris 4 года назад
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
@SauravKumar-si6yg
@SauravKumar-si6yg 4 года назад
@@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?
@ammarahsrahman18
@ammarahsrahman18 4 года назад
Please upload more videos on this, also with http header
@CodeWithChris
@CodeWithChris 4 года назад
Yes, there will be more videos like this! :) -Kat
@user-rc2nt1tb2u
@user-rc2nt1tb2u 3 года назад
. 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?
@CodeWithChris
@CodeWithChris 3 года назад
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
@miisolucky1879
@miisolucky1879 3 года назад
@CodeWIthChris is there a way to edit the information on a JSON extracted file and feed it back to the orginator?
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@benjamincleek7815
@benjamincleek7815 2 года назад
I know I'm late, but would love to see a demo of google earth and/or maps API!
@CodeWithChris
@CodeWithChris 2 года назад
Hello, Benjamin, can you kindly post your suggestion here: app.productstash.io/codewithchris#/ideas Thanks for learning with us! -Arthur
@allurisirisha3940
@allurisirisha3940 11 месяцев назад
Hey how to get this news API for my practice? can you please mention it in description box.
@bakdauletm5080
@bakdauletm5080 4 года назад
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?
@mikaelacaron4694
@mikaelacaron4694 4 года назад
Yes!! ALL production apps by companies will be UIKit, no one other than indies are using SwiftUI because it's brand new
@CodeWithChris
@CodeWithChris 4 года назад
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
@MissaMelodica
@MissaMelodica 4 года назад
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?
@CodeWithChris
@CodeWithChris 4 года назад
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
@MissaMelodica
@MissaMelodica 4 года назад
@@CodeWithChris Thanks. I went with an HTML parser instead.
@adilal-marzooq1582
@adilal-marzooq1582 4 года назад
Very nice. I would like to see an email validator API
@adrienvillez
@adrienvillez 4 года назад
I can't post a link here because RU-vid is gonna flag my comment, but Google "email validation Swift Github" and you'll find some pretty great things!
@adilal-marzooq1582
@adilal-marzooq1582 4 года назад
Adrien Villez thanks 👍🏻
@CodeWithChris
@CodeWithChris 4 года назад
Thanks. 👀👍 -Kat
@alexwarrener3770
@alexwarrener3770 4 года назад
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?!
@CodeWithChris
@CodeWithChris 4 года назад
Hello, you can use it as the source data for a tableview/colletionview for example - Francis
@markme7092
@markme7092 4 года назад
Please make video for adding image in core data
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for the suggestion! Check this out www.vadimbulavin.com/how-to-save-images-and-videos-to-core-data-efficiently/ -Kat
@dronesim
@dronesim 3 года назад
Spotify API would be amazing. Better yet, parsing the data and showing it in the front end
@CodeWithChris
@CodeWithChris 3 года назад
Cheers, thanks for suggesting that! :-) -Arthur
@davidleda2324
@davidleda2324 3 года назад
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!
@CodeWithChris
@CodeWithChris 3 года назад
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
@toanuk
@toanuk 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
Thank you! 🙌 - Kat
@Kunume_
@Kunume_ 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
Hello, it seems you used an array which is not a "key-value" pair. you can check out this video for reference ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-mJwmGpdZQAg.html - Francis
@salehal-shammari3510
@salehal-shammari3510 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
Hello, this video should help you learn about dictionaries, dont worry they will work the same - Francis
@pradeep8infosys
@pradeep8infosys 3 года назад
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?
@CodeWithChris
@CodeWithChris 3 года назад
Hello, maybe you can use the full stack notes app ru-vid.com/group/PLMRqhzcHGw1YSKIO61XncxTPoFu81K1Mx or CoreData tutorial ru-vid.com/group/PLMRqhzcHGw1aDYKmCuqXQ_IqpWpJlpoJ3 - Francis
@pradeep8infosys
@pradeep8infosys 3 года назад
@@CodeWithChris Thanks a lot.. Will check out all those 4 videos in the suggested Playlist..
@punkysuen
@punkysuen 4 года назад
Can I put struct of Article directly inside the NewsFeed.swift?
@CodeWithChris
@CodeWithChris 4 года назад
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
@JustinSletcherMusic
@JustinSletcherMusic 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
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
@jeffrosengarden6935
@jeffrosengarden6935 4 года назад
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!!!
@CodeWithChris
@CodeWithChris 4 года назад
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
@MyDataScienceTutor
@MyDataScienceTutor 4 года назад
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?
@CodeWithChris
@CodeWithChris 4 года назад
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
@adamhowley8037
@adamhowley8037 3 года назад
I know it isn't the focus of the video but what is the best way to manage API keys in Xcode?
@CodeWithChris
@CodeWithChris 3 года назад
Hello, that depends maybe you can put it in UserDefaults for quick saving and access - Francis
@rolandparnaso4612
@rolandparnaso4612 4 года назад
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 RU-vid)?
@CodeWithChris
@CodeWithChris 4 года назад
Hey Roland, right now, it doesn't remove ads but this is a good suggestion for the RU-vid membership.. i might upload the RU-vid videos on my course platform and make it available ad free for people in the YT membership.
@amitrai6471
@amitrai6471 4 года назад
Hey Chris make a video on OAuth Api
@CodeWithChris
@CodeWithChris 4 года назад
It's already added on our list, don't worry! We just have a very long list of topics to cover. 😄 -Kat
@Ivan_Maslov
@Ivan_Maslov 4 года назад
I would like to see Vk API. How to transform time(duration) into readable format(00:00 or 00:00:00), representing time unit
@CodeWithChris
@CodeWithChris 4 года назад
Thanks for the suggestion! I'll add it to the list. -Kat
@Ivan_Maslov
@Ivan_Maslov 4 года назад
CodeWithChris, I have figured out how to do that with DateComponentsFormatter.
@nileshjdarji
@nileshjdarji 2 года назад
do you have an example that shows how to create the json object with dictionary datatype.
@CodeWithChris
@CodeWithChris 2 года назад
"Hello, try checking out results from like itunes API or something it should be similar - Francis"
@ghuener
@ghuener 4 года назад
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...
@CodeWithChris
@CodeWithChris 4 года назад
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
@user-ec1dn3uz5k
@user-ec1dn3uz5k 3 года назад
Thanks a lot Chris! This means a lot. I messaged you on Twitter haven’t heard back 😃
@CodeWithChris
@CodeWithChris 3 года назад
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
@user-ec1dn3uz5k
@user-ec1dn3uz5k 3 года назад
@@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
@noelsoderstrom8706
@noelsoderstrom8706 2 года назад
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?
@CodeWithChris
@CodeWithChris 2 года назад
"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"
@dannydenovi29
@dannydenovi29 4 года назад
Hi Chris! How can I send a request or change a value in the JSON file with an action in my App?
@CodeWithChris
@CodeWithChris 4 года назад
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
@dannydenovi29
@dannydenovi29 4 года назад
CodeWithChris Thank you so much!
@neilbhosle2841
@neilbhosle2841 3 года назад
Can you make a video on parsing data by json serialisation
@CodeWithChris
@CodeWithChris 3 года назад
Thanks for your suggestion! :-) -Arthur
@neilbhosle2841
@neilbhosle2841 3 года назад
@@CodeWithChris Thanks, eagerly waiting for it....
@PeteTheGolfer1
@PeteTheGolfer1 3 года назад
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?
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@stuartthompson1943
@stuartthompson1943 4 года назад
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.)
@stuartthompson1943
@stuartthompson1943 4 года назад
This answered it for me. I was doing a web API call. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-tdxKIPpPDAI.html
@CodeWithChris
@CodeWithChris 4 года назад
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
@chadvader93
@chadvader93 3 года назад
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
@CodeWithChris
@CodeWithChris 3 года назад
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
@chadvader93
@chadvader93 3 года назад
CodeWithChris I could solve it now on my own by using the HTTP Header attribute „authorization“
@jamesqiu6715
@jamesqiu6715 2 года назад
@20:50 who teaches you to force unwrapped that "data" on line #38 ???
@CodeWithChris
@CodeWithChris 2 года назад
Hello, best if you talk to our tech support staff about this: codecrew.codewithchris.com. Thank you, James! -Arthur
@jamesqiu6715
@jamesqiu6715 2 года назад
@@CodeWithChris What I meant was that "data!" should be replaced as guard let validata = data else { fatalError () } even without any teaching / support staff help !
@haroonmazhar5212
@haroonmazhar5212 4 года назад
good
@CodeWithChris
@CodeWithChris 4 года назад
Thanks! 🙌
@TCakes
@TCakes 2 года назад
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?
@CodeWithChris
@CodeWithChris 2 года назад
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
@babarrauf7857
@babarrauf7857 3 года назад
Sir? Is there anyvideo regarding accessing json data in a zip file and then using that data to map our UI?
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@babarrauf7857
@babarrauf7857 3 года назад
@@CodeWithChris thank you very much sir, i hope your channel grows to be one of the best ❤️
@siento3239
@siento3239 3 года назад
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
@CodeWithChris 3 года назад
"Hello, this seems to be a common simulator issue recently, try changing to a different device - Francis"
@gauntletwielder6306
@gauntletwielder6306 4 года назад
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.
@CodeWithChris
@CodeWithChris 4 года назад
I'll add the Facebook API to the list. -Kat
@gauntletwielder6306
@gauntletwielder6306 4 года назад
CodeWithChris - Thank you. Much appreciated. 👍🏻😀
@EveyEverlasting
@EveyEverlasting 3 года назад
what about a local JSON fil thats part of your project?
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@tharlinhtet97
@tharlinhtet97 3 года назад
sir, i met with ATS block. what's wrong with me
@CodeWithChris
@CodeWithChris 3 года назад
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
@MrJamesieBoye
@MrJamesieBoye 3 года назад
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
@CodeWithChris
@CodeWithChris 3 года назад
"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"
@Hesham.Sultan
@Hesham.Sultan 3 года назад
I fixed it by using square brackets on newsfeed --> [newsfeed].self instead of newsfeed.self . I hope this helps
@volimpia
@volimpia 4 года назад
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!
@CodeWithChris
@CodeWithChris 4 года назад
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
@abhisheksagar5289
@abhisheksagar5289 2 года назад
can you make video on sunshine conversation api for facebook integration.
@CodeWithChris
@CodeWithChris 2 года назад
Thanks for your suggestion! Can you kindly post your suggestion here: app.productstash.io/codewithchris#/ideas :-) -Arthur
@bhawnasolanki8351
@bhawnasolanki8351 2 года назад
hello sir can you make project on moya
@CodeWithChris
@CodeWithChris 2 года назад
"Hello, sadly our channel only focuses on iOS content. Thank you for showing in the channel though, much appreciated - Francis"
@jamespatel3960
@jamespatel3960 2 года назад
API for iOS app please🙏
@CodeWithChris
@CodeWithChris 2 года назад
Thanks for dropping by! :) -Arthur
@davidwim
@davidwim 4 года назад
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!
@CodeWithChris
@CodeWithChris 4 года назад
Hello, you can send us your requests here: cwc.to/request - Kat
@nikolqy
@nikolqy 2 года назад
Would it kill you to put the code on github?
@CodeWithChris
@CodeWithChris 2 года назад
"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"
@nikolqy
@nikolqy 2 года назад
@@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 😂
@dineshkhatri3859
@dineshkhatri3859 2 года назад
dictionary inside array [{},{},{},]
@CodeWithChris
@CodeWithChris 2 года назад
You don't need the final comma, ;) @AdrienVillez
@jianqinzhao6617
@jianqinzhao6617 4 года назад
Facebook API please
@CodeWithChris
@CodeWithChris 4 года назад
Hello! Thanks for the suggestion, it's in our future topics list. :) - Kat
@dmitry3881
@dmitry3881 4 года назад
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
@CodeWithChris
@CodeWithChris 4 года назад
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
@dmitry3881
@dmitry3881 4 года назад
​@@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
@ibrahimkawar4685
@ibrahimkawar4685 Год назад
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
@CodeWithChris
@CodeWithChris Год назад
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
@ibrahimkawar4685
@ibrahimkawar4685 Год назад
Great thank you .
Далее
Data Flow in a SwiftUI App
33:15
Просмотров 52 тыс.
Learn JSON in 10 Minutes
12:00
Просмотров 3,1 млн
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
LISA - ROCKSTAR (Official Music Video)
02:48
Просмотров 34 млн
What Is JSON | Explained
5:44
Просмотров 37 тыс.
Using Generics to decode JSON
20:37
Просмотров 2,6 тыс.
SwiftData Basics in 15 minutes
15:18
Просмотров 38 тыс.
Core Data In SwiftUI | SwiftUI Core Data Tutorial
2:29:44
Learn JSON - Full Crash Course for Beginners
11:44
Просмотров 171 тыс.
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27