<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nitesh on Medium]]></title>
        <description><![CDATA[Stories by Nitesh on Medium]]></description>
        <link>https://medium.com/@nitpaxy?source=rss-2f54a9bcf1a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cArS1Ha4YSpvhIPoVdVpHQ@2x.jpeg</url>
            <title>Stories by Nitesh on Medium</title>
            <link>https://medium.com/@nitpaxy?source=rss-2f54a9bcf1a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:44:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitpaxy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Swift 3: API’s , JSON Data]]></title>
            <link>https://medium.com/aviabird/swift-3-apis-json-data-6ca749b550b3?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca749b550b3</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Mon, 27 Feb 2017 09:47:45 GMT</pubDate>
            <atom:updated>2017-03-02T13:18:37.688Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learning how API work in iOS and how to extract JSON</h4><h4>What is an API’s ?</h4><p>API stands for Application Programming Interface. It is a programmatic way to be able to access functions and data of other apps. Today pretty much every major platform has an API, most of them are free and you can access them to work with maps and location you can use facebook, twitter or google and all the data they have. So API’s allows you to access a huge amount of data and built apps that rely on existing systems like facebook or twitter.</p><h4>Why do we use API’s ?</h4><p>Do you use an application that tells you the location of your favorite restaurant? Or how about an app that shows when the next bus will be at your stop? Most tools like these rely on open APIs to run and pull the most accurate data. Those are both good examples of how open APIs might help you in your everyday life.</p><h4>How do we use API’s ?</h4><p>To demonstrate how this all works in iOS with Swift we are going to use the API of open whether map to get the weather of a particular location. So let’s get started go to <a href="http://openweathermap.org/">openwhethermap.org</a> and create an account. Once you have created an account the main important thing you are going to need is an API key which you will find on the website itself, copy it somewhere since we are going to be using it very shortly.</p><p>Now if you jump over to the API tab on the website you will find a bunch of API’s there, we are going to focus on the Current whether data API. Now if you click on the API Docs you will find the required API on it. But when you click on one of the API’s you will get 401 error, that is because you will have to provide your own API key instead of the existing one in the URL if you notice at the end.</p><blockquote><a href="http://samples.openweathermap.org/data/2.5/weather?q=London,uk&amp;appid=b1b15e88fa797225412429c1c50c122a1">http://samples.openweathermap.org/data/2.5/weather?q=London,uk&amp;appid=b1b15e88fa797225412429c1c50c122a1</a></blockquote><p>Change it with your own and you have your data in the form of JSON which looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*wYIo0j0AOsIV1F-pHHB82w.png" /></figure><p>This might not look very friendly but it is very powerful. JSON stands for Java Script Object Notation. It’s designed to simply store data in plane text format, and almost every programming language provides functions including Swift to process this data. Now let work towards it.</p><p>Create a new Swift project. Everything we are going to do will be in ViewController.swift. Let’s start by creating an URL with the one we have been provided by open whether map with your API key at the end.</p><p>If you notice the URL is HTTP and not HTTPs so we need to edit our <strong>info.plist</strong> to allow that domain name. There are various ways to do it so let us open the <strong>info.plist</strong> file as <strong>source code </strong>and add the code below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*PfzPtvZBLJcyNJ54JBi1Zw.png" /></figure><p>Now let’s go the ViewController and code. We will create an URL, create a task from the URL to go and get the content of that URL. Checking for an error and if there isn’t one then checking if we can work with the data with the help of <strong>JSONSerialization</strong> object, and we can then process the data so that we can work with the data in a usual swift manner. So let’s see how that looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*uiJ1aqYDK0DeyBQr4v-CCw.png" /></figure><p>jsonResult is the array in which you will have your data which will be printed in the console if you check. this is the same data you will use to display on your apps.</p><p>This is just a basic working of how an API works in Swift. With API’s, developers can quickly and inexpensively launch useful tools to benefit both the business and their customers. With an increasing number of businesses creating and adopting API’s into their systems, the best is yet to come.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca749b550b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-apis-json-data-6ca749b550b3">Swift 3: API’s , JSON Data</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: UICollectionView vs UITableView]]></title>
            <link>https://medium.com/aviabird/swift-3-uicollectionview-vs-uitableview-9909bbc0ec66?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9909bbc0ec66</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 07:20:53 GMT</pubDate>
            <atom:updated>2017-02-22T12:20:26.229Z</atom:updated>
            <content:encoded><![CDATA[<p>UICollectionView can do pretty much everything that UiTableView can do. The collection view is much more robust in terms of layout features and other things like animations. The way to set up both views with cell registration, dequeuing the cells, specifying size and heights are pretty much the same.</p><p>UITableView is the base mechanism for displaying sets of data on iOS. It’s a simple list, which displays single-dimensional rows of data. It’s smooth because of cell reuse and other magic.<br>UICollectionView is the model for displaying multidimensional data — it was introduced just a year or two ago with iOS 6, I believe.<br>The main difference between the two is how you want to display 1000 items. UITableViewhas a couple of styles of cells stacked one over the other. You should not try to bend it to do any other kind of things too much complex than that kind of layout.</p><p>UICollectionView is a much more powerful set of classes that allow modifying almost every aspect of how your data will appear on the screen, especially its layout but also other things. You can see UITableViews in almost every iOS application (for example Contacts or iPod), while UICollectionViews are more difficult to see (the grid in Photos, but also the over flow in iPod).</p><h4>Advantages of UICollectionView</h4><p>The biggest advantage of using collection view is the ability to scroll horizontally. If you have seen the AppStore app it has horizontal views which concept is used in many applications. If you want multiple columns in your apps then UICollectionView is the best way to do it. It is possible to have multiple columns in table view as well but it gets really messy since you are dealing with and array to display data in a table view. <br>UICollectionView Supports complex layouts. Apple provides you with something called UICollectionViewDelegateFlowLayout which provides you the flow of left and right as well as up and down. <br>UICollectionView can more easily implement drag and drop functionality which lets you manipulates things on the screen itself. If you try this with UITableView obviously you can’t do that. <br>UICollectionView supports custom animations based on different layouts which again cannot be done in UITableView. Advantages of collection view are endless but these are some major ones for me.</p><h4>Disadvantages of UICollectionView</h4><p>Major disadvantages of using UICollectionView is auto sizing of your cells, we don not really need auto sizing that much so it’s not that big of a problem. It takes a lot of trial and error to get auto sizing to work correctly ( not saying I’m good at it ). UITableView wins here as all you have to do is return UITableView automatic dimensions for the height of your row in each one of your cells.</p><p>So to sum this up, if you need something standard like most table views in iOS I will choose the UITableView, but if you need more control over your layout, go with UICollectionView.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9909bbc0ec66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-uicollectionview-vs-uitableview-9909bbc0ec66">Swift 3: UICollectionView vs UITableView</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: UICollectionView]]></title>
            <link>https://medium.com/aviabird/swift-3-uicollectionview-3f5d1a5e4815?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f5d1a5e4815</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[uicollectionview]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 07:17:39 GMT</pubDate>
            <atom:updated>2017-03-13T22:26:07.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rv4B91eqd9VzWMfGBcmAfg.jpeg" /></figure><h4>the one without storyboards</h4><p>Creating UICollectionView without storyboards is considered to be amongst the best practices as a developers. I like creating UICollectionView programmatically as they are easier to create and it creates very few bugs. UICollectionView is a highly customizable class for presenting your content in almost any layout you want. You can build Custom Layouts as it is a highly customizable class for presenting your content in almost any layout you want.</p><h4>Where do you start?</h4><p>Create a new Xcode project and build the app, you will get a white screen on the simulator which is a good start. Currently this app runs with Storyboard, so the very first step would be to delete the storyboard from the app. If you run the app now it should crash, but don’t worry the way for your application to not use a storyboard and do everything in code is very simple as well.</p><p>The error you get says that you are <em>missing a storyboard named main, </em>let’s fix that by going to the general section of the app and deleting <strong>main</strong> keyword from main interface. If you run the app again you get a black screen but the app does not crash, so it’s a good thing.</p><p>Since we don’t have a storyboard anymore we need to create a window manually through code. In the AppDelegate file, inside the <strong>didFinishLauncingOptions</strong> method we give properties to the window by giving frame and making the window visible. Now if you run the app you will have another crash which says that you do not have a <em>rootViewController, </em>hence we assign a root view controller.<em> </em>Which is also the final line step if you need to built an app without a storyboard. Down below is the required code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*heGQ19M1zRw2DlQM-DiGQA.png" /></figure><p>So far we have created an app without a storyboard which has a controller with a navigation bar. Assign a white background color to the view controller and run the app and you will have your controller in white. Now let’s go for the collection view.</p><h4>Adding collectionView to your Controller!</h4><p>First of all we need to subclass the ViewController from UIViewController to UICollectionViewController which is provided by apple and when you run the app it will crash. You will find a nasty error saying non-nil parameter, what it basically means is that you are missing a layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*PYm_9fQ9FTXE9cMFB5mG5g.png" /></figure><p>Now to fix this lets add a layout to the collection view in the AppDelegate file by creating a layout. Now when you run the app with the new layout app won’t crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*wrAXKSbHpic9LrHOao_L_A.png" /></figure><p><strong>Cells and stuff..</strong></p><p>Now that we have a collection view we need add number of cells to the view and we do that using <strong>numberOfItemsInSection </strong>method. Let’s say we need 5 cells. Next thing we do is we need to tell the UICollectionViewController what type of cell we need to return and we do that using <strong>cellForItemAt indexPath </strong>method<strong>.</strong></p><p>To make a collection view work we need to first register a cell to a matching identifier, the identifier is just a string. This might be a bit confusing but once you get used to it, it becomes easier. And now the only remaining thing to do is to dequeue the cells with the matching identifier.</p><p>The final thing we need to do is to provide size to these cells and we do that using <strong>sizeForItemAt indexPath </strong>method<strong>. </strong>This method will not work unless you have <strong>UICollectionViewDelegateFlowLayout </strong>included in your ViewController. Below is the code required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*LyKwNOeTL4Qjgze8kvYXsg.png" /></figure><p>If you run the app now you would find the simulator with 5 red blocks which are vertically scrollable. You can add your own custom cells to each blocks..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*KAldl5Ei9fDIDvJu3wy2jw.png" /></figure><p>That is how you build a collection view basically. Apple has provided a fantastic documentation, check out the UICollectionView <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionView_class/Reference/Reference.html">documentation</a>, experiment and explore new things.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f5d1a5e4815" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-uicollectionview-3f5d1a5e4815">Swift 3: UICollectionView</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: UITableView]]></title>
            <link>https://medium.com/aviabird/swift-3-uitableview-faad37d14c69?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/faad37d14c69</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[uitableview]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 07:13:56 GMT</pubDate>
            <atom:updated>2017-02-22T07:15:03.758Z</atom:updated>
            <content:encoded><![CDATA[<h4>the one without storyboard</h4><p>Creating UITableView without storyboards is fun. Let’s learn how to create table view without a storyboard (UI with pure programming code). Let’s first create a new Swift project and deleted the main.storyboard from the project. Now let’s add a view controller as the rootViewController in AppDelegate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*7cysEPP9QrzvGZxucH4oFA.png" /></figure><p>Now let’s included code to create a UITableView inside this view. Create a varible of type UITableView. Include the UITableViewDelegate, UITableViewDataSource. If you subclass ViewController to UITableViewController then these two methods are included and we do not need to add them separately. Give a background color to the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*b-OLLO14N4-ffSMO9VNxKQ.png" /></figure><p>We also need to register the cell you’re using, since you don’t have a storyboard. Also add frame to the tableview. Now add “numberOfRowsInSection” to specify how may rows you would like to have in your table view. Add “cellForRowAt indexPath” to create a cell. Now that we have dequeued the cell with the identifier add data to the cell.</p><p>Now it’s time to run the app..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*GrP8kqNEMfm1-DGQe8B1Eg.png" /></figure><p>You have your TableView which is been created without a storyboard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faad37d14c69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-uitableview-faad37d14c69">Swift 3: UITableView</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: Core Data.]]></title>
            <link>https://medium.com/aviabird/swift-3-core-data-7b00b50f5782?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b00b50f5782</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[core-data]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 07:09:01 GMT</pubDate>
            <atom:updated>2017-02-22T07:11:39.102Z</atom:updated>
            <content:encoded><![CDATA[<h4>the one with permanent data storage using database</h4><h3>What is Core Data?</h3><p>Core data is a built-in database storage that comes with iOS apps. Core data is one of those topics which are considered to be extremely confusing but it is actually not too bad once you have the grip of it. It allows permanent data storage but far more features that User Defaults.</p><p>So let’s gets started. While creating a new project in xcode make sure you have checked the core data button which will set up all of the core data for you. You will see a weird looking file name called .xcdatamodeledDon’t worry. It’s just like a spreadsheet file or you can call it a database structure. Click on it, and you will see Entities and Attributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*1iax33TorOmDCwXIIDS84Q.png" /></figure><p>We start off with Entity which is like a page on a spreadsheet or a table in a database. Lets’s rename Entity to Users which has two attributes username and password which are of String datatypes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*yxyfn6Mt_HTI2OsrEVOg6Q.png" /></figure><p>If we hop over to AppDelegate.swift file( this is a file which controls the basic functions of our app ) we can see that we have some new methods which allow us to work with core data. Now let’s write some code to save and restore data from CoreData database. Don’t forget to import CoreData in your ViewController.swift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*JltPa3ZbIh-UJpx4Sboy4A.png" /></figure><p>By creating the variables like appDelegate and context we can essentially use the context variable to store and restore data in the database. We set up the newUser variable with the help of entity Users and context which allows us to access the <strong><em>persistentContainer</em></strong> of the CoreData database. Once we have done that we can add some new users.</p><p>In <strong><em>do try catch </em></strong>we save the context. Do try catch is another construction to avoid app crashing in iOS. Now to be sure that it is saved we need to restore data from Core data.</p><p>We do it with what is known as a request using NSFetchRequest which returns an array. We run our request using again <strong><em>do try catch</em></strong>. This returns all the data present in the database as we have not added any constraints in our request. There are ways we can return specific kind of data as well.</p><p>Now run the app and see the data is stored in the database now and to make sure that the data is permanently stored shut down the app comment the saving part and then run the app again and you will notice that it returns the username and password. That is the basic idea of how the Core data works in swift.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b00b50f5782" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-core-data-7b00b50f5782">Swift 3: Core Data.</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: Optionals.]]></title>
            <link>https://medium.com/aviabird/swift-3-optionals-718941e89340?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/718941e89340</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[optionals]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Tue, 14 Feb 2017 06:51:43 GMT</pubDate>
            <atom:updated>2017-02-21T21:46:44.691Z</atom:updated>
            <content:encoded><![CDATA[<h4>the one with the empty variable.</h4><p>If classes and objects often confuses new programmers then it competes with Optionals as the most confusing topic for iOS developer, but it doesn’t have to be this way. So let’s spent just a few minutes to get really clear on what an optional is and how it works.</p><p>As we know that it is possible to create a variable that doesn’t have a value. So if i create a variable called number and give it a type it won’t give any error, however if i try and use that variable when it doesn’t have a value then you will an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*uI55n4ZnATdjie9nt3MR-w.png" /></figure><p>So if i want to create a variable that doesn’t have a value what i do is add <strong>? </strong>on to the end of the definition<strong>. </strong>Now the error message goes away and you could see the value printed is nil. <strong><em>So Optionals allow us to use variables without values without crasing our code.</em></strong></p><p>Now you might be wondering why on earth would i want a variable with no value in it, well you don’t necessarily need to define a variable like that but you might be doing something in your code that results in an outcome that you don’t know is going to have a value or not.</p><p>Let’s say for example user has entered some text that is a number ( remember if user enters a text it will always be string even if it is entered as a number ). Then what we will do is convert the number into an integer so that we could do something with it. There will be a straight of error and this is the error you will normally see when you encounter an optional.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*3hCo0sc1QmhYPEnq-J65KQ.png" /></figure><p>This error is saying user entered integer is an optional because it might have a nil value. So what we have to do is unwrap it saying the user entered text does have a value and can be multiplied.</p><p>But what if the user mistakenly enters a number 3 spelled out as in instead of entering “ 2 ” the user enters “ two ”, now this is going to give us an issue because we can’t convert the latter options as well as when we plan to use the variable as in multiply or divide and will get a nasty <strong>fatal error.</strong></p><p>So what is a good way around it then, well there is a construction which we will be using again and again. What we do is we put an if condition in front of the let command and then we don’t need to use the !.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*wLKBVYdkNWajKNDGAcwiGA.png" /></figure><p>The biggest advantage of this structure is if the user has entered an interview this would work perfectly fine, but if the user has not entered a value or has entered a wrong value then we won’t get a crash.</p><p>This us best way to deal with optionals is to have an if condition like above which tests whether or not they have a value or not. Where if there is a value you could do whatever you want with them if you don’t then there would be an error message. That is all you needs to known about optionals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=718941e89340" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/swift-3-optionals-718941e89340">Swift 3: Optionals.</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift 3: Permanently storing data]]></title>
            <link>https://medium.com/aviabird/the-one-with-userdefaults-aab2c2a7e170?source=rss-2f54a9bcf1a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/aab2c2a7e170</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[permanent-data-storage]]></category>
            <category><![CDATA[user-defalts]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Nitesh]]></dc:creator>
            <pubDate>Sun, 05 Feb 2017 10:06:44 GMT</pubDate>
            <atom:updated>2018-10-10T11:29:13.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNdDcGV8fUb2_hxIBaYhGg.png" /></figure><h4>The one with UserDefaults.</h4><p>Permanent data storage is an important skill to have under your belt as an iOS app developer. For most apps you are going to want to store some information about the user so that when they come back to the app they get their data straight away even after closing the app. There are number of ways to achieve this, we are looking at one of the simplest one in this section.</p><p>So what we are going to be using here is something called UserDefaults. Which as you might imagine is used to store some basic information about that particular user but really you can use to store any kind of information locally on the device.</p><p>This is very easy to setup as well. Open up a new xcode project and type the following code below in the viewDidLoad() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*5rdXVcyFNHDD9fOGVqDtmA.png" /></figure><p>We are saving the string(or any item) to UserDefaults which sets a variable called “key” and gives it a value “String” and when we want to bring that value back we just use the “key” which can be anything. When you run the app you will have your string printed out in the logs.</p><p>Now just to make sure that this has indeed saved data permanently let’s run the app again but this time we will comment out the saving part. This does the exact same thing (check logs again), which means that the data is stored permanently and we can access it whenever we load the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*mMqd6xlolh0yQxTjjzMNzw.png" /></figure><p>Basically you can store any kind of data into UserDefaults as in Objects like String, Date, Array, Integer and even Boolean. For that we need to create a global instance of UserDefaults.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*FYLR2yHqI--OA58Y8x6fhA.png" /></figure><p>Again comment out the storing values part and run the app, you will find the data is stored permanently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*QozA7unn5v-y4Kb3aKy_MA.png" /><figcaption>Logs</figcaption></figure><p>When retrieving objects, the result is optional. This means you can either accept the optionality, or typecast it to a non-optional type and use the <em>nil coalescing operator</em> to handle missing values. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*IhyXmGnift-p93Zj0kfBAQ.png" /></figure><p>So what we are checking here is are we able to take our name object and cast it to a string and if we are, then we print it. This is a much safer way of checking if the object exists and whether it’s of a certain type. That’s all about UserDefaults.</p><p>Note: NSUserDefaults has been renamed to UserDefaults standardUserDefaults() has been renamed to standard</p><h4>AVIACOMMERCE: OPEN SOURCE E-COMMERCE</h4><p>Aviacommerce is an open source e-commerce framework with an aim to simplify e-commerce ecosystem by creating and unifying smart services and providing consistent, cost-effective solution to sellers helping them sell more. visit <a href="https://aviacommerce.org/">aviacommerce.org</a> to know more.</p><figure><a href="https://aviacommerce.org/"><img alt="" src="https://cdn-images-1.medium.com/max/728/1*coayIQJPnBVvpb8McHO9AA.jpeg" /></a><figcaption>click the image to know more or visit <a href="https://aviacommerce.org/">https://aviacommerce.org</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aab2c2a7e170" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aviabird/the-one-with-userdefaults-aab2c2a7e170">Swift 3: Permanently storing data</a> was originally published in <a href="https://medium.com/aviabird">Aviabird</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>