<?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 Vikrant Dwivedi on Medium]]></title>
        <description><![CDATA[Stories by Vikrant Dwivedi on Medium]]></description>
        <link>https://medium.com/@vkrntdwivedi224?source=rss-dc346efdeb6e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sWE4veCIgsXiAOq7aLUJRg.png</url>
            <title>Stories by Vikrant Dwivedi on Medium</title>
            <link>https://medium.com/@vkrntdwivedi224?source=rss-dc346efdeb6e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 18:20:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vkrntdwivedi224/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[Login and Signup using Firebase in Swift]]></title>
            <link>https://blog.devgenius.io/login-and-signup-using-firebase-in-swift-8a63de282124?source=rss-dc346efdeb6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a63de282124</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Vikrant Dwivedi]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 07:16:43 GMT</pubDate>
            <atom:updated>2020-09-14T07:16:43.607Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we are going to learn how to set up your Swift app using Firebase and implement Signup and Login features.</p><ol><li><strong>What is Firebase</strong></li><li><strong>Creating and Configuring Swift app to use Firebase.</strong></li><li><strong>Implement Sign up functionality</strong></li><li><strong>Implement Login functionality.</strong></li></ol><p><strong>What is Firebase</strong></p><p>Firebase is a Backend-as-a-Service, it means we can implement features using Firebase that earlier needed back-end services. Earlier we need to either learn some back-end technology (Node.JS or Java) to build any mobile app if we want our app to implement Login/Sign up, data storage, etc.</p><p><strong>Creating and Configuring Swift app to use Firebase.</strong></p><p>To start, let’s create a new Single view Xcode project( I created with the name iOS-SwiftDemo).</p><p>To add Firebase in your iOS project, go to <a href="https://firebase.google.com/">https://firebase.google.com/</a> and select go to console from the top right. Follow the instructions to add a project. Once done, you get the screen like below where you can choose the platform you want to configure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TKm94Gm9qjaVk0nux0zxQ.png" /></figure><p>Select iOS and follow the instructions, on the next screen, you will be asked to enter the bundle identifier, enter your’s (this same bundle Id we will use in our Swift app as well).</p><p>In the next screen, there is a link to download the GoogleService-info.plist. This is the file that gets created automatically based on the details you entered and unique to your app.</p><p>Add the downloaded GoogleService-info.plist to your Swift file and click next.</p><p>Now, you will get the instructions to set up the Cocoapods in your app and that is very simple.</p><ol><li>Navigate to your project in your terminal.</li><li>Run <strong>pod init,</strong> a podifle will be created in your project root folder.</li><li>Copy the instructions from the firebase console and paste it in podfile.</li><li>Run <strong>pod install </strong>and it will install the required dependencies and create a new .xcworkspace file and from now on, we will open this in Xcode.</li></ol><p>Firebase setup is done here, now will move to the Swift app.</p><p>In our appdelegate file, import Firebase and in <strong>didFinishLaunchingWithOptions </strong>method, call FirebaseApp.configure()</p><p>If everything was done properly, by this time, you have a Swift app ready to use with Firebase.</p><p><strong>Implement Sign up functionality</strong></p><p>In order to create a user in Firebase, you need to go to your application in the firebase, and under the Authentication section, enable the sign-in method as Email/password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*44ka7jnnuoJsa9lto4b8gQ.png" /></figure><p><strong>Setup UI</strong></p><p>I have created a very simple UI to implement Sign up feature, it has an email and password field with a Signup button only. Setup your IbOutlet and Action and then will implement the click action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*VmYDR3s-99EIzBhfG8r0WQ.png" /></figure><p>Import FirebaseAuth in your view controller and paste below code in your button’s action.</p><p><strong>let</strong> email = emailTextField.text</p><p><strong>let</strong> password = passwordtextField.text</p><p>Auth.auth().createUser(withEmail: email!, password: password!) { (authResult, error) <strong>in</strong></p><p><strong>if</strong> <strong>let</strong> error = error {</p><p>print(“DEBUG: Failed to create user with error: “, error.localizedDescription)</p><p><strong>return</strong></p><p>}</p><p>print(“Sign up was successful”)</p><p>// Configure your navigation controller to navigate to the Home page</p><p>}</p><p>After the above code, when I entered the value in the Email and Password field and clicked the signup button, A new user gets created in Firebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agVAyH49wNvyNrLkQ2y3UA.png" /></figure><p><strong>Implement Login functionality</strong></p><p>To implement the sign-in feature, we just need to change the method name. Below is the code for Sign-in method.</p><p><strong>let</strong> email = emailTextField.text</p><p><strong>let</strong> password = passwordtextField.text</p><p>// Sign in method</p><p>Auth.auth().signIn(withEmail: email!, password: password!) { (user, error) <strong>in</strong></p><p>// handle error</p><p><strong>if</strong> <strong>let</strong> error = error {</p><p>print(“Unable to sign user in with error”, error.localizedDescription)</p><p><strong>return</strong></p><p>}</p><p>print(“Login was successful”)</p><p>}</p><p>}</p><p>When I entered the user details I just created, I got the below message in code and it means the login was successful.</p><p>That’s it for this article. Hope you enjoyed reading this and it will help you to use firebase in your next iOS app.</p><p>Feel free to give your suggestion/feedback in case I missed something to mention.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a63de282124" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/login-and-signup-using-firebase-in-swift-8a63de282124">Login and Signup using Firebase in Swift</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing an extension for setting up autolayout constraints in Swift]]></title>
            <link>https://blog.devgenius.io/writing-an-extension-for-setting-up-autolayout-constraints-in-swift-b6b5d56aa798?source=rss-dc346efdeb6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6b5d56aa798</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[extension]]></category>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Vikrant Dwivedi]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 19:43:28 GMT</pubDate>
            <atom:updated>2020-06-22T19:43:28.436Z</atom:updated>
            <content:encoded><![CDATA[<h3>Writing an extension for setting up auto layout constraints in Swift</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dxsKH4f5mZj0hbVf" /><figcaption>Photo by <a href="https://unsplash.com/@hakimr?utm_source=medium&amp;utm_medium=referral">hakim rahman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As we all know that for any iOS application, we need to use Autolayout to make our app look consistent on every device.</p><p>A storyboard is good for apps where we have few UI Controls on UI and we can easily setup Autolayout from Storyboard. However, if we create UI programmatically, we need to add constraints programmatically.</p><p>Setting up auto layout is easy in every ViewControllers if the number is less. However, if the App has more than 10–15 ViewController, which is the case with most of the medium or large scale applications, it’s not a good practice as you need to write similar code in most of your ViewControllers.</p><p>With Swift, you can solve this problem easily by writing an extension to UIView. Below is the code.</p><pre><strong>extension</strong> UIView {</pre><pre><strong>func</strong> <strong>addConstarint</strong>(top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?, paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat, width: CGFloat, height: CGFloat) {</pre><pre>translatesAutoresizingMaskIntoConstraints = <strong>false<br>// Use the top parameter to set the top constarint</strong></pre><pre><strong>if</strong> <strong>let</strong> top = top {<br><strong>self</strong>.topAnchor.constraint(equalTo: top, constant: paddingTop).isActive = <strong>true<br></strong>}<br><strong>// Use the left parameter to set the left constarint</strong></pre><pre><strong>if</strong> <strong>let</strong> left = left {<br><strong>self</strong>.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = <strong>true<br></strong>}<br><strong>// Use the bottom parameter to set the bottom constarint</strong></pre><pre><strong>if</strong> <strong>let</strong> bottom = bottom {<br><strong>self</strong>.bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom).isActive = <strong>true<br></strong>}<br><strong>// Use the right parameter to set the right constarint</strong></pre><pre><strong>if</strong> <strong>let</strong> right = right {<br><strong>self</strong>.rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = <strong>true<br></strong>}</pre><pre><strong>// Use the width parameter to set the top constarint<br>if</strong> width != 0 {<br>widthAnchor.constraint(equalToConstant: width).isActive = <strong>true<br></strong>}<br><strong>// Use the height parameter to set the top constarint</strong></pre><pre><strong>if</strong> height != 0 {<br>heightAnchor.constraint(equalToConstant: height).isActive = <strong>true</strong></pre><pre>}<br>}<br>}</pre><p>In the above <strong>addConstarint </strong>method, we used a number of arguments like the top, bottom, left, right, height, and width, so you can pass whatever constraints value you want to set.</p><p>You can call the above <strong>addConstarint </strong>method from any of your ViewController and you are good to go.</p><p>For better coding practices, place the above code in a separate file, call it <strong>AppExtension.swift</strong>, or whatever you want.</p><h3>Using UIView extension in ViewController</h3><p>Let’s use our extension in any viewController and see the magic. Suppose you have a button called signInButton where you want to add this extension to set up your constraints.</p><p>signInButton.<strong>addConstarint</strong>(top: <strong>PYV</strong>, left: <strong>PYV</strong>, bottom: <strong>PYV</strong>, right: <strong>PYV</strong>, paddingTop: <strong>PYV</strong>, paddingLeft: <strong>PYV</strong>, paddingBottom: <strong>PYV</strong>, paddingRight: <strong>PYV</strong>, width: <strong>PYV</strong>, height: <strong>PYV</strong>)</p><p><strong>*PSV: Pass your value</strong></p><p>With just above one line of code, you can set the auto layout to sign in button by passing the appropriate value as per your need.</p><p>I hope this will help you set up an auto layout in your app by creating an extension to UIView and call it from a multiple ViewController.</p><p>Please feel free in case you think I need to edit something or even with any suggestions. Always welcome.</p><p>Writing readable and non-repetitive code is the best way to improve your coding skills.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6b5d56aa798" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/writing-an-extension-for-setting-up-autolayout-constraints-in-swift-b6b5d56aa798">Writing an extension for setting up autolayout constraints in Swift</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>