<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nasir Ahmed Momin</title>
    <description>The latest articles on DEV Community by Nasir Ahmed Momin (@momin96).</description>
    <link>https://dev.to/momin96</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F257916%2F1203253f-66ac-41b9-923b-f7cb33b6273e.jpeg</url>
      <title>DEV Community: Nasir Ahmed Momin</title>
      <link>https://dev.to/momin96</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/momin96"/>
    <language>en</language>
    <item>
      <title>Flutter: Scroll Content on Keypad appears</title>
      <dc:creator>Nasir Ahmed Momin</dc:creator>
      <pubDate>Sun, 19 Jul 2020 06:43:43 +0000</pubDate>
      <link>https://dev.to/momin96/flutter-scroll-content-on-keypad-appears-562b</link>
      <guid>https://dev.to/momin96/flutter-scroll-content-on-keypad-appears-562b</guid>
      <description>&lt;p&gt;In the beginning for my Flutter journey, I struggled with scrolling the UI when Keypad appears on screen. Later I found out that it is pretty simple enough, I just have to use one single widget.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SingleChildScrollView()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Below is entire gist code &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JKkygVty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3i3tetzd29cdhc329xvg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JKkygVty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3i3tetzd29cdhc329xvg.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>textfield</category>
      <category>scrolling</category>
      <category>keypad</category>
    </item>
    <item>
      <title>Linked list implementation in Swift</title>
      <dc:creator>Nasir Ahmed Momin</dc:creator>
      <pubDate>Sun, 19 Jan 2020 05:01:46 +0000</pubDate>
      <link>https://dev.to/momin96/linked-list-implementation-in-swift-6lc</link>
      <guid>https://dev.to/momin96/linked-list-implementation-in-swift-6lc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Linked list according to Wikipedia:&lt;/strong&gt;&lt;br&gt;
   &lt;em&gt;It's a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes that together represent a sequence.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Types of a linked list.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Singly.&lt;/li&gt;
&lt;li&gt;Doubly.&lt;/li&gt;
&lt;li&gt;Circular.&lt;/li&gt;
&lt;li&gt;And many more.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Operations that we are going to perform.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a node from left/right.&lt;/li&gt;
&lt;li&gt;Remove Node from left/right.&lt;/li&gt;
&lt;li&gt;Size of the list.&lt;/li&gt;
&lt;li&gt;Search data in the list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here we 'll see only a Singly list.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qcE6gB7c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6y4dwqe14o4pi62bywnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qcE6gB7c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6y4dwqe14o4pi62bywnu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's define the structure for List&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Node&amp;lt;T&amp;gt; {
   var data: T?
   var next: Node&amp;lt;T&amp;gt;?

   init(_ data: T) {
       self.data = data
   }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As soon as to define this structure, you 'll hit with compilation error.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SEDEEyms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bus5p9bar0s3xvqzn0xl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SEDEEyms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bus5p9bar0s3xvqzn0xl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to the nature of &lt;code&gt;struct&lt;/code&gt; this issue obvious, as the compiler must know the size of struct in compile time. In this case, struct refers to itself which means there no definite size.&lt;br&gt;
 To resolve it, just change from &lt;code&gt;struct (value type)&lt;/code&gt; to &lt;code&gt;class (reference type)&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node&amp;lt;T&amp;gt;{
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here we are using a generic type called &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt; so that we can hold any type of data in the list.&lt;/p&gt;

&lt;p&gt;Define an &lt;code&gt;enum&lt;/code&gt; as direction for node manipulation.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum ListDirection {
    case left
    case right
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Define a structure for &lt;code&gt;SinglyLinkedList&lt;/code&gt; &amp;amp; functions to implement as shown below.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct SinglyLinkedList {

    // If nil, then there is NO node in list sequence.
    var firstNode: Node&amp;lt;T&amp;gt;?

    // Adds data/Item by creating node from specified direction.
    mutating func add(anItem item: T, from d: ListDirection) { }

    // Remove item from from specified direction.
    mutating func remove(from d: ListDirection) -&amp;gt; Node&amp;lt;T&amp;gt;? { }

    // fetch number of nodes available in linked list
    func getListSize() -&amp;gt; Int? { }

    // Search for item/data existance in list, returns true or false
    func search(anItem item: T?) -&amp;gt; Bool { }

    // Displays content of list
    func showListContent() { }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let's start the implementation of those function, the explanation will be available inline.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;add(anItem:from:)&lt;/code&gt; function&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Adds data/Item by creating node from a specified direction.
mutating func add(anItem item: T, from d: ListDirection) {

    // Create node by supplied data, to be added in list
    let newNode = Node&amp;lt;T&amp;gt;(item)

    // Validation check for node list does NOT exist, if true then, make new node as firstNode
    if firstNode == nil {
        self.firstNode = newNode
    }
    else {

        // Obtain firstNode reference.
        var tempNode = self.firstNode

        if d == .left { // Validation check for data insertion from Left side.
            // Make tempNode as next sequence for newly created node.
            newNode.next = tempNode

            // Make newNode as first node, so that new data empbed on left side.
            self.firstNode = newNode

        }
        else if d == .right { // Validation check for data insertion from Right side.

            // Note that the first node is never manipulated in this clause.
            // Traverse till it reaches nil
            while tempNode?.next != nil {
                tempNode = tempNode?.next
            }

            // Then insert new node from right side.
            tempNode?.next = newNode
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now create an instance of a singly linked list &amp;amp; start adding items in it.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var ll = SinglyLinkedList&amp;lt;Int&amp;gt;()
ll.add(anItem: 10, from: .left)
ll.add(anItem: 20, from: .right)
ll.add(anItem: 30, from: .left)
ll.add(anItem: 40, from: .left)
ll.add(anItem: 50, from: .right)
ll.add(anItem: 60, from: .right)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once we added items there is no way we can see it in action, for that we required a showListContent() function. Below is the implementation of it.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Displays content of list
func showListContent() {

    // Visible string to display sequence of data in list
    var visibleNodeSequence: String = ""

    var tempNode = self.firstNode

    // Travese till reaches end of list
    while tempNode != nil {

        if let str = tempNode?.data {
            visibleNodeSequence.append(contentsOf: String(describing:str))
            visibleNodeSequence.append(contentsOf:  tempNode?.next != nil ? " -&amp;gt; " : "")
        }

        // Incrementing by pointing to next node
        tempNode = tempNode?.next
    }

    print(visibleNodeSequence)
}

// Display content of list
ll.showListContent()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;On console, you can see output like this.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FIasT_88--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7m4c384gugl2zxhuwrid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FIasT_88--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7m4c384gugl2zxhuwrid.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;remove(from:) -&amp;gt; Node&amp;lt;T&amp;gt;?&lt;/code&gt; function&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Remove item from from specified direction.
mutating func remove(from d: ListDirection) -&amp;gt; Node&amp;lt;T&amp;gt;? {

    var nodeToBeRemoved: Node&amp;lt;T&amp;gt;?

    // return nil, incase of NO sequence exist
    if self.firstNode == nil {
        return nil
    }

    var nextNode = self.firstNode

    if d == .left {
        // Makes sure firstNode's next node becomes firstNode. so that firstNode from left side can be removed.
        self.firstNode = nextNode?.next
        nodeToBeRemoved = nextNode
    }
    else if d == .right {
        // Maintains a previous node, so that connection for node to be removed is deleted.
        var prevnode: Node&amp;lt;T&amp;gt;? = self.firstNode

        // Traverse till it reaches nil node
        while nextNode?.next != nil {
            // Both points to same node, then next node is incremented to point to next of next
            prevnode = nextNode
            nextNode = nextNode?.next
        }

        // Connection deleting for node to be removed
        prevnode?.next = nil
        nodeToBeRemoved = nextNode
    }

    return nodeToBeRemoved
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;getListSize()-&amp;gt;Int?&lt;/code&gt; function&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// fetch number of nodes available in linked list
func getListSize() -&amp;gt; Int? {

    // Validation check for first node is nil.
    guard firstNode != nil else { return nil }

    var tempNode = firstNode

    // Maintian a counter to loop
    var noOfNodes = 0

    // Traverse till it reaches nil node
    while tempNode != nil {
        // If not nil then increment counter
        noOfNodes += 1
        // Increment node by pointing to next node
        tempNode = tempNode?.next
    }

    return noOfNodes
}

// Get size of linked list
ll.getListSize()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;search(anItem:) -&amp;gt; Bool&lt;/code&gt; function&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Search for item/data existance in list, returns true or false
func search(anItem item: T?) -&amp;gt; Bool {

    guard firstNode != nil else { return false }

    var tempNode = self.firstNode

    while tempNode != nil {

        if tempNode?.data == item {
            // Once item exist return true.
            return true
        }

        // Increment node by pointing to next node
        tempNode = tempNode?.next
    }

    return false
}

// Searches item 40 in list
ll.search(anItem: 40)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>swift</category>
      <category>linkedlist</category>
      <category>datastructure</category>
    </item>
    <item>
      <title>iOS Chat App with XMPP framework</title>
      <dc:creator>Nasir Ahmed Momin</dc:creator>
      <pubDate>Sat, 21 Dec 2019 07:50:52 +0000</pubDate>
      <link>https://dev.to/momin96/ios-chat-app-with-xmpp-framework-53n0</link>
      <guid>https://dev.to/momin96/ios-chat-app-with-xmpp-framework-53n0</guid>
      <description>&lt;p&gt;Wants to build Chat App for iOS?&lt;/p&gt;

&lt;p&gt;Lets gets started&lt;br&gt;
XMPP stands for Xtensible Messaging &amp;amp; Presence Protocol. &lt;/p&gt;

&lt;p&gt;Things required ?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;IM Server (I prefer MongooseIM)&lt;/li&gt;
&lt;li&gt;User (Account created)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can download MongooseIM Package here &amp;amp; Install package&lt;br&gt;
&lt;a href="https://www.erlang-solutions.com/resources/download.html"&gt;https://www.erlang-solutions.com/resources/download.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Details for installation can be found here &lt;a href="https://mongooseim.readthedocs.io/en/latest/user-guide/Getting-started/"&gt;https://mongooseim.readthedocs.io/en/latest/user-guide/Getting-started/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On installation completes launch Terminal &amp;amp; execute following command &lt;br&gt;
&lt;code&gt;$ mongooseimctl start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then Check status&lt;br&gt;
&lt;code&gt;$ mongooseimctl status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When All thats done. You need a user, head down below &amp;amp; create user&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ mongooseimctl register &amp;lt;user&amp;gt; &amp;lt;host&amp;gt; &amp;lt;password&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Eg: &lt;code&gt;$ mongooseimctl register user1 localhost qwerty&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can verify user creation &lt;code&gt;$ mongooseimctl registered_users localhost&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Till now server config &amp;amp; user creation completed.&lt;/p&gt;

&lt;p&gt;Before jumping into code part, lets understand following things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JID&lt;/li&gt;
&lt;li&gt;Stanza &amp;amp; its type.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Stream.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;JID&lt;/strong&gt;: is something by which each individual is uniquely identified is XMPP. It does looks like this
&lt;code&gt;username@hostname/resource&lt;/code&gt;
username: is local part
hostname: is domain part
resource: is resource part which is optional in many cases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stanza&lt;/strong&gt;: is name of XML tag/piece that sends &amp;amp; received. Basic Stanza's are &amp;lt; message &amp;gt; &amp;lt; presence &amp;gt; &amp;amp; &amp;lt; iq &amp;gt;, details will be mentioned about them, if required in future&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stream&lt;/strong&gt;: is entry point for interprocess communication to start on shared file called Socket, which happens by &amp;lt; stream &amp;gt; tag.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We shall start working on iOS App.&lt;br&gt;
I hope you guys knows how to create Xcode iOS Project &amp;amp; Pod setup.&lt;/p&gt;

&lt;p&gt;In Podfile  &lt;code&gt;pod 'XMPPFramework'&lt;/code&gt;&lt;br&gt;
then run &lt;code&gt;pod install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create XMPPController.swift file &amp;amp; make a singleton object.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class XMPPController: NSObject {
    static let sharedInstance = XMPPController()
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now declare an XMPPStream instance &amp;amp; intilize it in &lt;code&gt;init()&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var stream: XMPPStream?
override init() {
  self.stream = XMPPStream()
  super.init()
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also declare following vars.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var hostName: String?
var userJID: XMPPJID?
var hostPort: UInt16?
var password: String?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Declare a connect function as below&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func connect(withHostName name: String, userJID jid: String, hostPort port: UInt16, password pwd: String) {

    guard let uJID = XMPPJID(string: jid) else {
        return
    } 

    hostName    = name
    userJID     = uJID
    hostPort    = port
    password    = pwd

    // Stream Configuration
    stream?.hostName = name
    stream?.myJID = uJID
    stream?.hostPort = port
    stream?.startTLSPolicy = .allowed

    if stream!.isDisconnected {
        do {
            try stream?.connect(withTimeout: 10)
        }
        catch let e {
            print(e.localizedDescription)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once we reached till here, we have forgot most important thing.&lt;br&gt;
without confirming delegate of stream our &lt;code&gt;XMPPController&lt;/code&gt; wont able to receive any callbacks, add following lines in &lt;code&gt;init&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;self.stream?.addDelegate(self, delegateQueue: DispatchQueue.main)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;XMPPStreamDelegate&lt;/code&gt; as set of delegate functions among them we will use only couple of, add following code as below&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extension XMPPController: XMPPStreamDelegate {
    func xmppStreamDidConnect(_ sender: XMPPStream) {
       print("Stream Connected")
       try! stream?.authenticate(withPassword: password!)
    }

    func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
       print("Stream: Authnticated")
       stream?.send(XMPPPresence())
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once &lt;code&gt;xmppStreamDidConnect(:XMPPStream)&lt;/code&gt; is connected, we are making sure that authentication should initiate &amp;amp; on authentication &lt;code&gt;xmppStreamDidAuthenticate(:XMPPStream)&lt;/code&gt; will receive callback&lt;/p&gt;

&lt;p&gt;Entire code is available on github repo&lt;br&gt;
&lt;a href="https://github.com/momin96/Mobile-Chat-App"&gt;https://github.com/momin96/Mobile-Chat-App&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xmpp</category>
      <category>ios</category>
      <category>instantmessaging</category>
    </item>
  </channel>
</rss>
