<?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 Abhishek Kumar on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Kumar on Medium]]></description>
        <link>https://medium.com/@abhishek1nacc?source=rss-5f0d0935c4b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rDVo3elU1cODhVFBsD6XhA.jpeg</url>
            <title>Stories by Abhishek Kumar on Medium</title>
            <link>https://medium.com/@abhishek1nacc?source=rss-5f0d0935c4b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 13:12:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhishek1nacc/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[iOS Important Questions (Part 1)]]></title>
            <link>https://medium.com/ios-expertise/ios-important-questions-part-1-2794191660e3?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2794191660e3</guid>
            <category><![CDATA[ios-interview-question]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 07:56:36 GMT</pubDate>
            <atom:updated>2020-10-21T08:35:13.293Z</atom:updated>
            <content:encoded><![CDATA[<h3>iOS Interview Questions (Part 1)</h3><p><strong>Q1: Difference between setNeedsLayout and layoutIfNeeded ?</strong></p><p><strong><em>setNeedsLayout</em></strong>: Invalidates the current layout of the receiver and triggers a layout update during the next update cycle. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance.</p><p><strong>layoutIfNeeded: </strong>Lays out the subviews immediately, if layout updates are pending. Use this method to force the view to update it&#39;s layout immediately.</p><p>Used mostly when updating the constraints of views/subviews dynamically at run time, these methods are used to update the constraints on the views.</p><p><strong>Q2: What are content compression resistance and hugging priority and how it works?</strong></p><p><strong>Content Hugging Priority:</strong></p><p>Sets the priority with which a view resists being made larger than its intrinsic size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*_u3DcxSOoXtOV19weXrmhA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*WNIrIwPHIkLCcuZux1QRTQ.png" /></figure><p><em>Hugging priority comes into action when available size is more than the total size of the content.</em> Label 2 with higher priority hugs its content more and make the Label1 expand more than its intinsic content. Content Hugging priority for Label 1 is 250 and for Label 2 is 251. So Label 2 having more hugging priority will resist being larger than its content (intrinsic size). Label 1 will expand in size beyond its intrinsic size in order to satisfy the constraints.</p><p><strong>Compression Resistance Priority :</strong></p><p>Sets the priority with which a view resists being made smaller than its intrinsic size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*zCtbPu0dfdaTovUOC5TtXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*uCP_3eMN8XrJ6zQT3IPK8A.png" /></figure><p>Here Label 1 compression resistance is greater than label 2 so label 1 will not truncate and it’s size will not be decrease beyond it’s intrinsic size and Label 2 will truncate instead to maintain the constraint rules.</p><p><strong>Q3: What are Size Classes and how it can be used to design user interface for different screen sizes in portrait and landscape mode ?</strong></p><p>Size Classes are the iOS method of creating adaptable layouts that look great on all sizes and orientations of iPhone and iPad. With Size Classes, you don’t think about orientation or even device size. You care about whether you are running in a compact size or regular size, and iOS takes care of mapping that to various device sizes and orientations. The system defines two size classes, <em>regular</em> (denotes expansive space) and <em>compact</em>(denotes constrained space), which describe the height and width of a view.</p><p>A view may possess any combination of size classes:</p><ul><li>Regular width, regular height</li><li>Compact width, compact height</li><li>Regular width, compact height</li><li>Compact width, regular height</li></ul><p>Using these combination as a developer we can handle UI for all the screen sizes with different orientations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*P8uX92tVSUAztUCPcyGJIg.png" /></figure><p><strong>Q4: What are IBDesignable and IBInspectable ?</strong></p><p>The <strong>@IBInspectable</strong> keyword lets you specify that some parts of a custom <strong>UIView</strong> subclass should be configurable inside Interface Builder. Only some kinds of values are supported (booleans, numbers, strings, points, rects, colors and images) but that ought to be enough for most purposes. it’s possible to build a custom interface for configuring your custom controls and have them rendered in real-time while designing your project.</p><p>Using IBDesignable class, and IBInspectable properties it is easier to use the custom views in interface builder (xib / storyboard) and change the properties in interface builder, We don’t need to run and check the shape, size and color of our custom views. It can be done through the interface builder.</p><p><strong>Q5 : What are StackView and How to use them ?</strong></p><p><strong>UIStackView</strong> gives us: a flexible, Auto Layout-powered view container that makes it even easier to build complex user interfaces. It is a streamlined interface for laying out a collection of views in either a column or a row. Horizontal stack view can be used to lay out views horizontally and auto layout will be take care by stack view, Alignment, Axis, and Spacing can be used to change how views will look inside the stack view. Stack view need to be provided autolayout but it’s child doesn’t.</p><p><strong>Q6: What is BitCode ? Why you should enable it when uploading the app to app store ?</strong></p><p>Bitcode is an intermediate representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the store.</p><p>By enabling the bitcode you ensure that all the performance/optimization done in the LLVM framework will recompile your app without asking you to upload the app again which will reduce the size of your app in future LLVM updates.</p><p><strong>Q7: How to reduce app size ?</strong></p><ul><li>Enable bitcode so that app can be recompiled by LLVM and LLVM framework improvements can be reflected in app binary without need to resubmit your app.</li><li>Use Asset catalog instead of directly putting images to folder.</li><li>Use On demand resource for images which are not used frequently.</li><li>Analyse your app size for compressed size (download size) and uncompressed size (Installed size) on app store connect for different variants.</li><li>Delete unused images and assets from your code.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2794191660e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-expertise/ios-important-questions-part-1-2794191660e3">iOS Important Questions (Part 1)</a> was originally published in <a href="https://medium.com/ios-expertise">iOS Expertise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UIViewController LifeCycle]]></title>
            <link>https://medium.com/@abhishek1nacc/uiviewcontroller-lifecycle-b9c5053401de?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9c5053401de</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uiviewcontroller]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Sun, 18 Oct 2020 10:10:53 GMT</pubDate>
            <atom:updated>2020-10-18T10:10:53.621Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s important to understand how view is created, loaded, rendered, and displayed by UIViewController.</p><p>Below are the various stages:</p><ul><li>loadView()</li><li>loadViewIfNeeded()</li><li>viewDidLoad()</li><li>viewWillAppear(_ animated:Bool)</li><li>viewWillLayoutSubviews()</li><li>viewDidLayoutSubviews()</li><li>viewDidAppear(_ animated: Bool)</li><li>viewWillDisappear(_ animated: Bool)</li><li>viewDidDisappear(_ animated: Bool)</li></ul><ol><li><strong>loadView:</strong></li></ol><p>This method is called by view controller when it’s view property is requested. This method loads or create a view and assign it to the <strong>view</strong> property.</p><p>If the view controller has an associated nib file, this method loads the view from the nib file.</p><p>This is where subclasses should create their custom view hierarchy if they aren’t using a nib. Should never be called directly. Only override this method when you programmatically create views and assign the root view to the view property Don&#39;t call super method when you override <a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview">loadView</a></p><p><strong>2. loadViewIfNeeded</strong>:</p><p>Loads the view controller’s view if it has not yet been loaded. Calling this method loads the view controller’s view from its storyboard file, or creates the view as needed based on the established rules.</p><p><strong>3. viewDidLoad:</strong></p><p>This is called when the view is created and loaded into the memory but the bound for the view are not defined yet. Initialise the objects that view controller is going to use.</p><p><strong>4. viewWillAppear:</strong></p><p>Notifies the view controller that its view is about to be added to a view hierarchy.</p><p><strong>5. viewWillLayoutSubviews:</strong></p><p>Called to notify the view controller that its view is about to layout its subviews.When a view’s bounds change, the view adjusts the position of its subviews. Your view controller can override this method to make changes before the view lays out its subviews. The default implementation of this method does nothing.</p><p><strong>6. viewDidLayoutSubviews:</strong></p><p>This event notifies the view controller that the subviews have been setup. It is a good place to make any changes to the subviews after they have been set.</p><p><strong>7. viewDidAppear:</strong></p><p>Notifies the view controller that its view was added to a view hierarchy. You can override this method to perform additional tasks associated with presenting the view.</p><p><strong>8. viewWillDisappear:</strong></p><p>Notifies the view controller that its view is about to be removed from a view hierarchy. This method is called in response to a view being removed from a view hierarchy. This method is called before the view is actually removed and before any animations are configured.</p><p><strong>9. viewDidDisappear:</strong></p><p>Notifies the view controller that its view was removed from a view hierarchy. You can override this method to perform additional tasks associated with dismissing or hiding the view.</p><p><em>viewWillLayoutSubviews and </em><em>viewDidLayoutSubviews will also be called at other times when subviews of the main view are loaded, for example when cells of a table view or collection view are loaded.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9c5053401de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS App Life Cycle]]></title>
            <link>https://medium.com/@abhishek1nacc/ios-app-life-cycle-f39fcff4a850?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f39fcff4a850</guid>
            <category><![CDATA[ios-basics]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-lifecycle]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 08:11:26 GMT</pubDate>
            <atom:updated>2019-07-20T08:11:26.812Z</atom:updated>
            <content:encoded><![CDATA[<p>During startup, the UIApplicationMain function sets up several key objects and starts the app running. At the heart of every iOS app is the UIApplication object, whose job is to facilitate the interactions between the system and other objects in the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*3dfIX6sEnUu2BN-_m38wNA.png" /></figure><p>The UIApplication object manages the event loop and other high-level app behaviors. It also reports key app transitions and some special events (such as incoming push notifications) to its delegate, which is a custom object you define.</p><p>The app delegate is the heart of your custom code. This object works in tandem with the UIApplication object to handle app initialization, state transitions, and many high-level app events. This object is also the only one guaranteed to be present in every app, so it is often used to set up the app’s initial data structures.</p><h3>Main Run Loop</h3><p>Run loops are part of the fundamental infrastructure associated with threads. A <em>run loop</em> is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none. Your application does not need to create these objects explicitly; each thread, including the application’s main thread, has an associated run loop object. Only secondary threads need to run their run loop explicitly, however. The app frameworks automatically set up and run the run loop on the main thread as part of the application startup process.</p><p>An app’s <em>main run loop</em> processes all user-related events. The <a href="https://developer.apple.com/documentation/uikit/uiapplication?source=post_page---------------------------">UIApplication</a>object sets up the main run loop at launch time and uses it to process events and handle updates to view-based interfaces. As the name suggests, the main run loop executes on the app’s main thread. This behavior ensures that user-related events are processed serially in the order in which they were received.</p><p><strong>Application states:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*g1Kj8uQ7OZCd8HplCefGfQ.png" /></figure><ul><li><strong>Not Running — </strong>Either the application has not started yet or was running and has been terminated by the system.</li><li><strong>Inactive — </strong>An application is running in the Foreground but is not receiving any events. This could happen in case a Call or Message is received. An application could also stay in this state while in transition to a different state. In this State, we can not interact with app’s UI.</li><li><strong>Active — </strong>An application is running in the Foreground and receiving the events. This is the normal mode for the Foreground apps. The only way to go to or from the Active state is through the Inactive state. User normally interacts with UI, and can see the response/result for user actions.</li><li><strong>Background — </strong>The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.</li><li><strong>Suspended — </strong>The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YPQ-oRQ__izABZYNyH58A.png" /></figure><p>Below are the UIApplication delegate methods which can be implemented to handle app’s data, states, push notifications, and tranisitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJkuRs4wzKge4S7YCdPm4Q.png" /></figure><ul><li><strong>didFinishLaunchingWithOptions</strong> : Called when application launch.</li><li><strong>applicationWillResignActive</strong> :<em> Sent when the application is about to move from active to inactive state.</em><strong><em> This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks.</em></strong><em> Games should use this method to pause the game.</em></li><li><strong>applicationDidEnterBackground</strong> : <em>Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.</em></li><li><strong>applicationWillEnterForeground :</strong> <em>Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.</em></li><li><strong>applicationDidBecomeActive</strong> : <em>Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.</em></li><li><strong>applicationWillTerminate :</strong> <em>Called when the application is about to terminate. Save data if appropriate.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f39fcff4a850" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic & Static Dispatch (Swift)]]></title>
            <link>https://medium.com/@abhishek1nacc/dynamic-static-dispatch-swift-e6e87a462a2a?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6e87a462a2a</guid>
            <category><![CDATA[polymorphism]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Tue, 16 Jul 2019 20:31:44 GMT</pubDate>
            <atom:updated>2019-07-16T20:31:44.895Z</atom:updated>
            <content:encoded><![CDATA[<p>Compiled programming languages have three primary methods of dispatch at their disposal: <strong><em>direct dispatch, table dispatch, and message dispatch.</em></strong></p><h3>Direct Dispatch (static dispatch) :</h3><p>Direct dispatch is the fastest style of method dispatch. However, direct dispatch is also the most restrictive from a programming point of view, and it is not dynamic enough to support subclassing.</p><h3>Table Dispatch :</h3><p>Table dispatch is the most common implementation of dynamic behavior in compiled languages. Table dispatch uses an array of function pointers for each method in the class declaration. Most languages refer to this as a “virtual table,” but Swift uses the term “witness table.” Every subclass has its own copy of the table with a different function pointer for every method that the class has overridden. As subclasses add new methods to the class, those methods are appended to the end of this array. This table is then consulted at runtime to determine the method to run.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*BEt_UAhhQqcSAQL2y0YJng.png" /></figure><p>In this scenario, the compiler will create two dispatch tables (lookup tables). One for A and B:</p><p>A having function pointers for method1 and method2.</p><p>B will have method1, method2, and method3.</p><p>this method of dispatch is still slow compared to direct dispatch. From a byte-code point of view, there are two additional reads and a jump, which contribute some overhead.</p><p>Let see the code below and what will be the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*258LwbPSSyjdFiY9vFphOw.png" /></figure><p>In above example, Movable protocol has been extended to add crawl functionality which is not declared in protocol itself. So here static disptach or direct dispatch occur i.e reference type verison is called at compile time.</p><p>Now, if we declare crawl() as part of original protocol declaration, Animal version of function is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*rcAx1leHIr3IZCvdIKQIFw.png" /></figure><p>Dynamic dispatch is also called as runtime polymorphism.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6e87a462a2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[atomic nonatomic retain assign copy]]></title>
            <link>https://medium.com/@abhishek1nacc/atomic-nonatomic-retain-assign-copy-582b79d31568?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/582b79d31568</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[copy]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Tue, 07 May 2019 14:18:00 GMT</pubDate>
            <atom:updated>2019-05-07T14:18:00.303Z</atom:updated>
            <content:encoded><![CDATA[<p>Atomic and NonAtomic has been one of the most debated and wrongly documented by some of the developers in their blogs. Let’s understand once for all.</p><h3>Atomicity:</h3><p><strong>Atomic</strong> (default) : <em>Atomic is the default: if you don’t type anything, your property is atomic.An atomic property is guaranteed that if you try to read from it, you will get back a valid value. It does not make any guarantees about what that value might be, but you will get back good data, not just junk memory. What this allows you to do is if you have multiple threads or multiple processes pointing at a single variable, one thread can read and another thread can write.</em></p><p><strong>If they hit at the same time, the reader thread is guaranteed to get one of the two values: either before the change or after the change.</strong></p><p><em>What atomic does not give you is any sort of guarantee about which of those values you might get</em>. Atomic is really <strong>commonly confused with being thread-safe</strong>, and that is not correct. You need to guarantee your thread safety other ways. However, atomic will guarantee that if you try to read, you get back some kind of value.</p><p><em>NonAtomic : On the flip side, non-atomic, as you can probably guess, just means, “don’t do that </em><em>atomic stuff.” What you lose is that guarantee that you always get back something. If you try to read in the middle of a write, you could get back garbage data. But, on the other hand, you go a little bit faster. Because atomic properties have to do some magic to guarantee that you will get back a value, they are a bit slower. If it is a property that you are accessing a lot, you may want to drop down to nonatomic to make sure that you are not incurring that speed penalty.</em></p><h3>Access :</h3><p>The second category of property attributes you can have are ones that modify access. There are also two in this class: readonly and readwrite</p><p><strong><em>readonly : </em></strong>readonly makes it so this property is read-only. There is no setter for it at all.</p><p><strong><em>readwrite</em></strong><em>(default) : readwrite</em>, allows both read and write. That is the default; again, if you do not write anything, you have a readwrite property.</p><h3>Storage:</h3><h4>strong (default) :</h4><p>The default is called strong. Strong just means you have a reference to an object and you will keep that object alive. As long as you hold that reference to the object in that property, that object will not be deallocated and released back into memory.</p><h4>weak :</h4><p>Strong’s analog is weak. Weak gives you a reference so you can still “talk” to that object, but you are not keeping it alive. If everyone else’s strong references go away, then that object is released. The nice thing about weak references is that they will automatically nil references that go away. If you have a reference to an object and all of the strong references to it go away and it gets deallocated, your weak reference does not point to some junk memory, which can give you crashes. It will just automatically nil itself out.</p><h4>assign :</h4><p>assign is the keyword used for primitives. It is pretty easy to understand: If you do not have an object, you cannot use strong, because strong tells the compiler how to work with pointers. But if you have a primitive (i.e. int, float, bool, or something without the little asterisk after the type), then you use assign, and that makes it work with primitives.</p><h4>retain :</h4><p><em>increases the retain count of an object by 1.</em> Takes ownership of an object.</p><p><strong>copy : </strong>Makes a copy of an object, and returns it with retain count of 1. If you copy an object, you own the copy. This applies to any method that contains the word copy where “copy” refers to the object being returned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=582b79d31568" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS App threats and Security]]></title>
            <link>https://medium.com/@abhishek1nacc/ios-app-threats-and-security-782a1d44d08c?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/782a1d44d08c</guid>
            <category><![CDATA[ssl-pinning]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios-security]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Sun, 05 May 2019 15:05:58 GMT</pubDate>
            <atom:updated>2019-05-05T15:05:58.346Z</atom:updated>
            <content:encoded><![CDATA[<p>iOS OS is consider safer platform and more secure as compare to android platform.</p><p>But still it can be hacked and prone to attack and stealing of sensitive user data</p><p>class-dump-z command line utility called <a href="https://code.google.com/p/networkpx/wiki/class_dump_z">class-dump-z</a> that will display all the Objective-C declaration information found in the executable. Using this you can see which all frameworks are used.</p><p>When you submit your app to the App Store, Apple encrypts your binary with FairPlay encryption — the same type of encryption used for some iTunes content. Running class-dump-z on an encrypted binary will result in complete gibberish. But, it’s can be decrypted by hackers, the process can be completed manually in about 10 minutes time and there are even tools that exist to automate it. Long story short, you must plan and expect your application to be decrypted. You must plan that attackers will see your classes, methods, instance variables, protocols… everything.</p><p>Mistakes that developers make which can be used by attackers:</p><h3>- Property Lists Are Vulnerable :</h3><p>Attackers can easily get access to your property list and if you have stored some critical &amp; sensitive data or even some logic in your app which depends upon those properties, then in that case things can go haywire.</p><h3>- User Defaults: Not Secure!</h3><p>Remember how silly of an idea it was to save sensitive information in a plist? Well, guess what NSUserDefaults is? Yep, that’s a plist as well. The physical location for the NSUserDefault plist can be found at: <strong>{App Directory}/Library/Preferences/{Bundle Identifier}.plist</strong>.</p><p>If attackers can access plist files even while the iOS device is locked, where is a safe place to put information? One potential solution is to encrypt the data going into NSUserDefaults. You would then need to do a sanity check whenever you load the data to see if that data is actually valid.</p><h3>Keychain Access :</h3><p>Another potential solution is to migrate sensitive data away from plists and put it in the iOS Keychain.</p><p>Keychain Access ups the ante for the attacker. Attackers will be unable to access critical information while the device is locked. However, it’s important to not put too much trust solely in the keychain system.</p><p>Here is why: Keychain is an Apple-maintained database of important information. It is encrypted with the help of the user’s password, which generally is the simple 4-digit numeric passcode.</p><p>If an attacker were to try to get past this using the hacker’s version of brute force, they could potentially figure out the password in about 20 minutes. After figuring out the password, they can simply run a command line utility that can dump the keychain database.</p><p>What can you do about this? Here are Keychain best practices:</p><ul><li>Make sure you make an attacker’s life a little harder by encrypting the data using <strong>Apple’s Common Crypto APIs</strong> found in the Security Framework</li><li><strong>Be aware of your methods and how an attacker can use them:</strong> Your beautiful encryption/decryption method could be the best thing out there, but attackers can control the runtime and run your decryption method on your encrypted data.</li></ul><h3><strong>Network Penetration :</strong></h3><p>Attackers also like to see what’s occurring on the network side of an application. A quick and dirty way to see if any interaction could occur on the device is to check for any URLs in the application binary.</p><p>Then using tools those requests can be intercepted and original response can be modified.</p><p>Use HTTPS instead of HTTP :</p><h3>TLS Security Guarantees</h3><p><a href="https://developer.apple.com/library/archive/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECGLOSSARY">HTTPS</a> is defined by <a href="http://www.ietf.org/rfc/rfc2818.txt">RFC 2818</a> but, for the most part, it consists of a simple composition of two existing protocols:</p><ul><li><a href="https://developer.apple.com/library/archive/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECGLOSSARY">HTTP</a> (as defined by <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616 Hypertext Transfer Protocol — HTTP/1.1</a> and others)</li><li><a href="https://developer.apple.com/library/archive/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECGLOSSARY">TLS</a> (as defined by <a href="http://www.ietf.org/rfc/rfc5246.txt">RFC 5246 The Transport Layer Security (TLS) Protocol Version 1.2</a> and others), or the older <a href="https://developer.apple.com/library/archive/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECGLOSSARY">SSL</a> protocol</li></ul><p>HTTPS inherits its security guarantees from TLS. By default these are:</p><ul><li>on-the-wire privacy —<strong><em> This guarantees that the data is secure from a passive attacker</em></strong> (someone who can see but can’t modify the packets exchanged between the client and server).</li><li>client-authenticates-server authentication — This protects the client from an active attacker (someone who can both see and modify the packets exchanged between the client and the server). Most importantly, it protects the client from various forms of <strong>man-in-the-middle attack,</strong> including impostor servers (servers who pretend to be the real server and thus acquire confidential information from the client).</li></ul><h3>SSL Pinning</h3><p>SSL pinning technique helps us deal with one of the most common security attacks — <a href="https://www.owasp.org/index.php/Man-in-the-middle_attack">MITM</a> or man-in-the-middle.</p><p>With SSL pinning, we can refuse all connections except the ones with the designated server whose SSL certificate we’ve saved into our local bundle.</p><p>Read this <a href="https://infinum.co/the-capsized-eight/how-to-make-your-ios-apps-more-secure-with-ssl-pinning">article</a> for more <a href="https://infinum.co/the-capsized-eight/ssl-pinning-revisited">detail</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=782a1d44d08c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[User Defined Build Setting]]></title>
            <link>https://medium.com/@abhishek1nacc/user-defined-build-setting-f4bba59a5d6c?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4bba59a5d6c</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[user-build-settings]]></category>
            <category><![CDATA[own-settings]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Fri, 03 May 2019 22:14:49 GMT</pubDate>
            <atom:updated>2019-05-03T22:14:49.050Z</atom:updated>
            <content:encoded><![CDATA[<p>During development and deployment of app, you need to use 2–3 kind of server urls depending upon develop (staging mode), and production mode (deployment or market release).</p><p>So, How we can maintain 2 urls and make it automated without need to change some variable, or using some boolean or even macros everytime you need to point to particular server.</p><p>Best way is to use User defined build settings feature provided in Xcode.</p><p>The process involves 3 steps.</p><ol><li>Add user defined settings in your target’s build settings.</li><li>Add a key in your Info.plist file that uses your recently defined build setting.</li><li>Read the value via Info.plist in your code.</li></ol><h4>1) Adding Build Settings in Xcode</h4><p>Select your project in the ‘Project Navigator’, your target, build settings and click the ‘+’ icon on the bar below to add user settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NV8tdW6cQcfrZ3kkdhPKxw.png" /></figure><h4>2. Adding a Key in Info.plist</h4><p>Select the Info.plist file from the project navigator in Xcode. Hover on the last row and click ‘+’ to add another below. Enter the ‘ServerUrl’ in the key and $(SERVER_URL) in the value part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFLJGL_x89LZoUs8cTDUJA.png" /></figure><p>Here, we are accessing the build setting that we just added. At run time, anything that is inside $() is replaced by its actual value in the build settings. In our case our SERVER_URL setting will be placed here. You can also notice other similar entries in the Info.plist like bundle identifier, bundle name etc.</p><h4>3. Read the value via Info.plist</h4><p>Bundle class provides a method to access values defined in Info.plist using corresponding keys.</p><pre>let serverUrl = Bundle.main.object(forInfoDictionaryKey: “ServerURL”) as! String</pre><pre>print(serverUrl)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4bba59a5d6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Codable Protocol (Encoding & Decoding)]]></title>
            <link>https://medium.com/@abhishek1nacc/codable-protocol-encoding-decoding-b11e06c878de?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b11e06c878de</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[codable]]></category>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[json-parsing]]></category>
            <category><![CDATA[decoding]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Fri, 03 May 2019 18:59:51 GMT</pubDate>
            <atom:updated>2019-05-03T18:59:51.434Z</atom:updated>
            <content:encoded><![CDATA[<p>Many programming tasks involve sending data over a network connection, saving data to disk, or submitting data to APIs and services.These tasks often require data to be encoded and decoded to and from an intermediate format while the data is being transferred.</p><p>The Swift standard library defines a standardized approach to data encoding and decoding. You adopt this approach by implementing the <a href="https://developer.apple.com/documentation/swift/encodable">Encodable</a> and <a href="https://developer.apple.com/documentation/swift/decodable">Decodable</a> protocols on your custom types.</p><p>Adopting these protocols lets implementations of the <a href="https://developer.apple.com/documentation/swift/encoder">Encoder</a> and <a href="https://developer.apple.com/documentation/swift/decoder">Decoder</a>protocols take your data and encode or decode it to and from an external representation such as JSON or property list.</p><h3>Encode and Decode</h3><p>The simplest way to make a type codable is to declare its properties using types that are already Codable. These types include standard library types like <a href="https://developer.apple.com/documentation/swift/string">String</a>, <a href="https://developer.apple.com/documentation/swift/int">Int</a>, and <a href="https://developer.apple.com/documentation/swift/double">Double</a>; and Foundation types like <a href="https://developer.apple.com/documentation/foundation/date">Date</a>, <a href="https://developer.apple.com/documentation/foundation/data">Data</a>, and <a href="https://developer.apple.com/documentation/foundation/url">URL</a>. Any type whose properties are codable automatically conforms to Codable just by declaring that conformance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sf-5yY1cUxV3JSGpwF9hYg.png" /></figure><p><strong>CodingKeys </strong>: <em>Choose Properties to Encode and Decode</em></p><p>Codable types can declare a special nested enumeration named CodingKeys that conforms to the <a href="https://developer.apple.com/documentation/swift/codingkey">CodingKey</a> protocol.</p><p>When this enumeration is present, its cases serve as the authoritative list of properties that must be included when instances of a codable type are encoded or decoded. The names of the enumeration cases should match the names you’ve given to the corresponding properties in your type.</p><p>Omit properties from the CodingKeys enumeration if they won&#39;t be present when decoding instances, or if certain properties shouldn&#39;t be included in an encoded representation. A property omitted from CodingKeys needs a default value in order for its containing type to receive automatic conformance to Decodable or Codable. If the keys used in your serialized data format don’t match the property names from your data type, provide alternative keys by specifying String as the raw-value type for the CodingKeysenumeration. The string you use as a raw value for each enumeration case is the key name used during encoding and decoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGF_FPT5-EWleJqXaoqELQ.png" /></figure><p><strong>Read Data From Arrays</strong></p><p>When the JSON you use contains a homogeneous array of elements, you add a conformance to the Codable protocol on the individual element’s type. To decode or encode the entire array, you use the syntax [Element].self.</p><p>In the example below, the GroceryProduct structure is automatically decodable because the conformance to the Codable protocol is included in its declaration. The whole array in the example is decodable based on the syntax used in the call to the decode method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8_AYskorRWfPlQMx6WFIA.png" /></figure><p>If the JSON array contains even one element that isn’t a GroceryProduct instance, the decoding fails.</p><p><strong>Change Key Names</strong></p><p>Names you use in your Swift code don’t always match the names in JSON that refer to the same values. When working with the JSONEncoder and JSONDecoder classes in Swift, you can easily adopt conventional Swift names in your data types even when using JSON that requires the use of other names.</p><p>To create a mapping between Swift names and JSON names, you use a nested enumeration named CodingKeys within the same type that adds conformance to Codable, Encodable, or Decodable.</p><p>In the example below, see how the Swift property name points is mapped to and from the name “product_name” when the property is encoded and decoded.</p><p>This phenomena and way has make Json parsing simple and robust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwC6Qb7WT6pp2qyuzaSxHA.png" /></figure><p>Although the name description is consistent between the two representations, you still include it in the CodingKeys enumeration because it’s a value required by the GroceryProduct structure. Its enumeration case doesn’t need an explicit raw value because its name is the same as the corresponding property name.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b11e06c878de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVC MVVM MVP VIPER]]></title>
            <link>https://medium.com/@abhishek1nacc/mvc-mvvm-mvp-viper-a229363379bb?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a229363379bb</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[viper]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Tue, 23 Apr 2019 19:35:30 GMT</pubDate>
            <atom:updated>2019-04-23T19:35:30.433Z</atom:updated>
            <content:encoded><![CDATA[<p>Why do we need architecture ? This is the first things to understand before getting into different kinds of them.</p><ul><li>It simplifies code for writing and reading.</li><li>Isolate complex or frequently changing code.</li><li>Avoid bugs and more robust to scale.</li><li>Divide and Separate functionalities, View, and business logic into pieces which are sytematic to develop and easy to debug as well.</li><li>Easy to Write test cases with dependency injection and protocol oriented programming.</li></ul><p>Different pieces or Options of architectures :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHVsjgr7E5aYO_pdIqxiSA.png" /></figure><p>Common Architectural models:</p><h3>MVC</h3><p>MVC is a default architecture for iOS and widely used by Apple as well. Practically it is good architecture for small applications, But for large applications Controller ends up becoming huge with business logic, view rendering logic, view presenter or prepare logic (for example tableView cells view logic), network, and database logic in single file. It makes difficult to debug, maintenance headache, very tedious to write Unit XCTest cases.</p><p>Basically Controller (ViewController) owns View and Model objects with model updates when something changes via KVO, and NotificationCenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQ5Ce-8gS8XR_YBK5rsUIg.png" /></figure><p>Having stated Cons for this architecture, It is the most used architecture for iOS apps till now as it is default architecture when we create new project from Xcode.</p><h3><strong>MVP</strong></h3><p>Model View Presenter add Presenter layer which prepares data needed for the view. For example a common case is request data from REST api, parse that data and populate TableView/CollectionView using that data.</p><p>So, In that case we can make NetworkService class with responsibility for making http request using URLSession. Let say Json data which is recieved is array of Employee. Then We can have Model class with Employee name with name, salary, department, position as properties. So, Once data is received from network, dictionary with JSON can be send in completion handler and View controller will initiate parser and View Controller having presenter object is then passed parsed values</p><p>Presenter can have [Employee] property for tableView and also any calculation or computation needed for tableView cell population should be done in presenter class only. In MVC if you have done same thing then all the computation and calculation are done in View Controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DKfxM6vt15QNnWus1kdzWg.png" /></figure><h3><strong>MVVM</strong></h3><p>In MVVM Presenter is called as View Model. This architecture are same as MVP. Only difference is MVVM uses Data Binding in which View changes then Model updates using some kind of listener or binding, and when Model changes View updates using binding. Binding is achieved using Reactive programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psno-dv3jvYqhyGsS3mnvw.png" /></figure><h3><strong>VIPER</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GB_u_sZJdFdBxVHZIoJZnA.png" /></figure><p>In Viper few more pieces or separation are added:</p><ul><li>Entity: It’s an object that represents the data and that can be passed around with little to no logic in them.</li><li>Presenter: Presenter is prepares data for View with the help of Interactor. all date formatting logic for view, computed data, tableView cell data are part of this layer.</li><li>Interactor: Interactor is a class which Presenter can go to for data and Presenter doesnot have to worry about Database and Network. Interactor interacts with Modal and Presenter layer.</li><li>Router : It’s a coordinator which takes care of navigation from one page to other. All navigation logic is move from View to Router.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a229363379bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MultiThreading issues and counter measures]]></title>
            <link>https://medium.com/@abhishek1nacc/multithreading-issues-and-counter-measures-f3c59d7ca3de?source=rss-5f0d0935c4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3c59d7ca3de</guid>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[race-condition]]></category>
            <category><![CDATA[deadlock]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Abhishek Kumar]]></dc:creator>
            <pubDate>Sun, 21 Apr 2019 15:09:46 GMT</pubDate>
            <atom:updated>2019-04-24T06:12:05.978Z</atom:updated>
            <content:encoded><![CDATA[<h3>Multithreading issues and counter measures</h3><p>There are 3 main issues which can occur in concurrent environment where many threads try to access and modify the same section (critical section) and which can lead to unexpected ambiguous results and crashes which are very hard to debug and find in production code.</p><p>Let see what are the 3 most common issues in below sections with coding practice and measures to prevent them.</p><p><strong>Priority Inversion :</strong></p><p>As the name suggests, Priority inversion is a scenario in which low priority thread get access or lock to critical section and high priority queue has to wait for the signal of low priority thread signal. If suppose there are 100 more threads with mid level or moderate quality of service trying to getting access to shared resource. In that case high priority thread has to wait for the other threads and is being starved of CPU time and It is called as Thread Starvation.</p><p><strong>CounterMeasure:</strong></p><p>It’s better to use Semaphores only among threads of the same priority.</p><p><strong>DeadLock:</strong></p><p><strong><em>Deadlock</em></strong> refers to a specific condition when two or more processes or threads are each waiting for another to release a resource, or more than two processes are waiting for resources in a circular chain</p><p>Deadlock is a common problem in multiprocessing where many processes share a specific type of mutually exclusive resource known as a lock.</p><p>Let see some examples and common scenarios in which deadlock can occur:</p><ul><li>Suppose there are 2 resources A and B and there are 2 threads with one as high priority and other as low priority. And both thread need both the resources for their tasks to finish.</li><li>Let say we take 2 semaphore to protect each resources A and B for locking so that once one thread access the resource other cannot enter untill the unlock signal from former thread.</li><li>Now Thread 1 with high priority locks Resource A and Thread 2 locks Resource B. Thread 2 need Resource A access for finishing it task and then only it can release lock from resource B. Similarly Thread 1 locks Resource A and wait for Resource B which is locked by Thread 2. This is classic case of deadlock.</li></ul><p>Solution :</p><p>Avoiding <a href="https://en.wikipedia.org/wiki/Deadlock">deadlocks</a> is not simple. The best solution would be preventing them by writing code that <a href="https://en.wikipedia.org/wiki/Deadlock_prevention_algorithms">can’t possibly reach this state</a>.</p><p>DeadLock In Synchronisation:</p><p>Never call sync on same queue especially Main Thread because <strong>Synchronous</strong> returns control to the current queue only after the task is finished. It blocks the queue and waits until the task is finished.</p><p>See below screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exSROSB8zFzNVEtGhib85w.png" /></figure><p>Here global().sync blocks the current thread which is main thread and main.sync will block current thread/queue which is global and try to get access to main queue which was previously being blocked by global sync queue and main queue is released only after outer queue task is completed and which depends upon inner queue which in turn requires main thread.</p><p>So, In short never use main synchronously, except inside async global queue.</p><blockquote><strong>Race condition</strong> — A <strong>race condition</strong> happens when two or more threads access a shared data and change it’s value at the same time.</blockquote><p>Suppose we have a bank account with balance as 1000. Transaction can be done by ATM and by online. If user use his debit card to withdraw 700 and at the same time uses online payment to buy some goods worth 600. Then this lead to corrupted system. To avoid this synchronisation technique like Semaphore and mutex locks can be used.</p><p>How to Avoid threading issues in concurrency or multithreading environment:</p><ol><li>Better Design with avoiding shared resources among multiple threads.</li><li>Using Locks like NSLock or DispatchSemaphore but this can lead to priority inversion or deadlock if not coded and designed correctly.</li><li>Using Serial Dispatch queues.</li><li>Using barrier flag with concurrent queue so that when</li></ol><p>When dispatching a code block to a concurrent queue, you can assign a flag to it indicating that it is a barrier task, meaning that <strong>when it is time to execute this task, it should be the only executing item on the specified queue.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ii9RPCIcVh5bUhc912RMSg.png" /><figcaption>When task 5 is excuting then other task will not be executed at that time frame.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x17kXtk4A7ZUpulg5FAwQA.png" /><figcaption>Barrier flag example.</figcaption></figure><p><strong><em>Summary</em></strong> :</p><p>Race Condition : Race condition happens when a critical section is modified at the same time by two threads which leads in crash or invalid state of system.</p><p>DeadLock: DeadLock happens when 2 threads need resource of one another to break the lock and neither can release the resource for other because of their waiting for each other resource.</p><p>Priority Inversion : Priority Inversion is phenomenon when low priority thread locks the critical section and high priority thread are executed later after low priority thread unlocks the section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3c59d7ca3de" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>