<?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[inspace labs - Medium]]></title>
        <description><![CDATA[We are a software house that loves crafting beautiful web&amp;mobile apps with the great idea. - Medium]]></description>
        <link>https://medium.com/inspace-labs-blog?source=rss----51d2f60ae8f1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>inspace labs - Medium</title>
            <link>https://medium.com/inspace-labs-blog?source=rss----51d2f60ae8f1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:18:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/inspace-labs-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Social Service File Browser inside iOS App]]></title>
            <link>https://medium.com/inspace-labs-blog/social-service-file-browser-inside-ios-app-b249e3381ab6?source=rss----51d2f60ae8f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/b249e3381ab6</guid>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dropbox]]></category>
            <dc:creator><![CDATA[Michał Zaborowski]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 10:54:40 GMT</pubDate>
            <atom:updated>2017-10-09T12:26:01.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*GyZqljuJidBT_Cqq1z7lMQ.png" /></figure><p><a href="https://github.com/inspace-io/Social-Service-Browser"><strong>SocialServiceBrowser</strong></a><strong> </strong>is a library that provides a simple way to browse, preview and import files from external service like Dropbox, Amazon Drive, Google Drive etc. I written it to be generic, it is possible to integrate you custom service, all you need to do is implement some protocol methods, and thats it. It support custom UI/layout and is based on UICollectionViewController, below you will find how default UI look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*zQIr44o8HOd7oakFPQGdBA.gif" /></figure><p>It was originally written to import files from external services, but i thought that might be usefull to preview also files, so in example which you find on <a href="https://github.com/inspace-io/Social-Service-Browser">GitHub</a> you will find how to use it with <strong>UIDocumentInteractionController</strong></p><h3>Usage</h3><p>I wanted to be as simple as possible, so if you want to use to with Dropbox, there is already class which implements preview and import functionality. Usage is limited to few lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b075fc22bc6371cfd70139fd3d04f394/href">https://medium.com/media/b075fc22bc6371cfd70139fd3d04f394/href</a></iframe><h3>Your custom service integration</h3><p>To be able to implement custom browser client all you need to do is implement methods from <strong>SocialServiceBrowserClient</strong> protocol:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c16b126fa1a15be030482aed01ec910/href">https://medium.com/media/0c16b126fa1a15be030482aed01ec910/href</a></iframe><p>In addition to that you have to implement <strong>SocialServiceBrowserNode</strong>protocol for each node (file/directory).</p><pre>@objc public protocol SocialServiceBrowerNode {<br>   var nodeId: String? { get }<br>   var isDirectory: Bool { get }<br>   var nodeName: String { get }<br>   var path: String? { get }<br>}</pre><p>The easiest way to integrate it with some external SDK, would be to use extensions. I have created sample client for Dropbox and used <a href="https://github.com/dropbox/SwiftyDropbox">SwiftyDropbox</a>. Below you can see how easy it was to integrate it using extensions. <a href="https://github.com/dropbox/SwiftyDropbox">SwiftyDropbox</a> returns collection of Files.Metadata nodes, they created subclasses for files <strong>Files.FileMetadata</strong> and directories <strong>Files.FolderMetadata</strong>but for my purpose i have created extension for parent class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d94155c8c5476d3a7f17cc347f77fa4a/href">https://medium.com/media/d94155c8c5476d3a7f17cc347f77fa4a/href</a></iframe><p>The last step would be to handle methods of <strong>SocialServiceBrowserClient</strong>protocol, here is how it is done for Dropbox client:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbe20bf0c004dc7be656d006c9c54a64/href">https://medium.com/media/dbe20bf0c004dc7be656d006c9c54a64/href</a></iframe><p>Hope soon we will cover implementation for each common social service.</p><p>I recommend you to check example and source code which is available in our <a href="https://github.com/inspace-io/Social-Service-Browser">GitHub repositery here!</a> — enjoy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b249e3381ab6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inspace-labs-blog/social-service-file-browser-inside-ios-app-b249e3381ab6">Social Service File Browser inside iOS App</a> was originally published in <a href="https://medium.com/inspace-labs-blog">inspace labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tasting gradle flavors in android project.]]></title>
            <link>https://medium.com/inspace-labs-blog/tasting-gradle-flavors-in-android-project-720dcf9f289e?source=rss----51d2f60ae8f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/720dcf9f289e</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Piotr Moskała]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 07:31:01 GMT</pubDate>
            <atom:updated>2017-10-09T07:31:01.106Z</atom:updated>
            <content:encoded><![CDATA[<h3>Imagine that..</h3><p>Imagine that we’ve got Android app project with core code base which can be supplied to different clients with changed resources like colors, strings, drawables, launcher icons etc. How to deal with it? Answer is pretty straightforward — gradle flavors.</p><p>Before we get into it , let’s assume we’ve got three environments for development , staging and production. Call them debug, staging and release.</p><p>Our build.gradle file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf6dc595a9d0bac9a5aec841586f518f/href">https://medium.com/media/bf6dc595a9d0bac9a5aec841586f518f/href</a></iframe><p>With one, even five flavors it’s okay, but what if there are 20, 50 or 100 flavors ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o7btPCcdNniyf0ArS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcbc-comedy-what-3o7btPCcdNniyf0ArS&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2F3o7btPCcdNniyf0ArS%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="242" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d1318098f44d184d067e99d069338d/href">https://medium.com/media/94d1318098f44d184d067e99d069338d/href</a></iframe><h3><strong>How to deal with them?</strong></h3><p>When we’d create 10 , 20 or 50 flavors, which with 3 build types will actually give you so many build variants, the file is going to be huge and so hard to read. You can easily split it up to smaller, variant specific ones and apply them to the main build.gradle file while project is syncing up.</p><p>When we have to add something specific for particular flavor, it’s much more easier to do it within specific file than diving into one big build.gradle file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3678e020b78f544bb12cc65c1aa8eff/href">https://medium.com/media/b3678e020b78f544bb12cc65c1aa8eff/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*zoes2av6HY_td-Bs3y-3Kw.png" /><figcaption>Project structure after splitting build.gradle file.</figcaption></figure><p>As expected it gave us 3 variants for one flavor. In the code snippet below you can see build.gradle for <em>clientA</em> flavor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddadb53c958c7621128e8ef27447f15a/href">https://medium.com/media/ddadb53c958c7621128e8ef27447f15a/href</a></iframe><h3><strong>Add libraries which need specific applicationId to work.</strong></h3><p>Sometimes some of the libraries need applicationId to work, so we can’t easily add them. One of the examples is NMI payment processor library.</p><p>We’ve got two options:</p><ul><li>We can add dependencies section to your flavour specific gradle file</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec587aebc041fd8af9a5ab5e434c766f/href">https://medium.com/media/ec587aebc041fd8af9a5ab5e434c766f/href</a></iframe><ul><li>Just do it automatically for all of them within app’s build.gradle file using simple groovy method</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b29bd85ede7b08f1354bca06efc17203/href">https://medium.com/media/b29bd85ede7b08f1354bca06efc17203/href</a></iframe><p>Seems to work fine, doesn’t it ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtsgNNs93oIbwk%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fstar-trek-nod-tsgNNs93oIbwk&amp;image=http%3A%2F%2Fgiphygifs.s3.amazonaws.com%2Fmedia%2FtsgNNs93oIbwk%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="327" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd03789fc19da3055980ae31b4f1ded0/href">https://medium.com/media/bd03789fc19da3055980ae31b4f1ded0/href</a></iframe><h3><strong>Gradle plugins differences (2.3.2 vs 3.0.0-beta)</strong></h3><p>Since 3.0.0 this problem is reduced and builds are faster than ever, but if we don’t use the latest version of Android studio for some reasons, we can struggle with resolving dependencies for all of the variants. In this case the best option would be to specify for which variant we’d want to compile all dependencies. We can easily do that by reuse code from point 3:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c712a6c9a8f9007dcce61e23f1f03e3/href">https://medium.com/media/1c712a6c9a8f9007dcce61e23f1f03e3/href</a></iframe><p>This solution has one disadvantage. You have to put your dependencies list into external array e.g. into root build.gradle file. As you may noticed we called it as :</p><pre>rootProject.ext.dependencyList</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56d670d4b19147f05bd51f02957007f0/href">https://medium.com/media/56d670d4b19147f05bd51f02957007f0/href</a></iframe><p>It has some cons like gradle can’t check our libraries versions, so we have to take care of it by ourselves. In my case in one of the big projects with more than 100 flavors which implicates 300 variants build time on TravisCI server has been decreased from 36mins to 13–15mins for gradle android plugin 2.3.2. That’s huge improvement though.</p><p>Like I said I tested AS 3.0 and according to Gradle’s official <a href="https://blog.gradle.org/blazing-fast-android-builds">blog post</a>, lot of improvements had been provided and this shouldn’t be a problem anymore.</p><h3>Conclusions</h3><p>I know that these solutions won’t fit for everyone. We haven’t used dimensions in this case, but the whole idea can be tweaked to use them. That’s not a problem.</p><p>You’ve got any questions or suggestions you want to share with us we’re opened to further discussion.</p><p>You can find those examples as a whole working project on <a href="https://github.com/inspace-io/android-flavors">our github page</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=720dcf9f289e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inspace-labs-blog/tasting-gradle-flavors-in-android-project-720dcf9f289e">Tasting gradle flavors in android project.</a> was originally published in <a href="https://medium.com/inspace-labs-blog">inspace labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to observe changes on single instance of NSManagedObject]]></title>
            <link>https://medium.com/inspace-labs-blog/how-to-observe-changes-on-single-instance-of-nsmanagedobject-f64532f36ef4?source=rss----51d2f60ae8f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/f64532f36ef4</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[core-data]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Michał Zaborowski]]></dc:creator>
            <pubDate>Wed, 11 May 2016 09:35:46 GMT</pubDate>
            <atom:updated>2016-05-11T13:10:37.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*5xUtIZ1pZz1DXnLzO_VEpQ.png" /></figure><p>In this post I will describe how to observe changes on single NSManagedObject instance. Motivation to wrote this article was my friend, who asked me:</p><blockquote><em>“How do you observe changes on single object in CoreData? I know that there is NSFetchedResultsController but is it worth to observe only one object with it?!”</em></blockquote><p>Of course it is possible to use NSFetchedResultsController but is was created for different things, if you read <a href="https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/">documentation</a> you can find this:</p><blockquote><em>“You use a fetched results controller to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView object. (…) While table views can be used in several ways, fetched results controllers are primarily intended to assist you with a master list view.</em>”</blockquote><p>My answer was — don’t do it in this way. The most efficient way to do it is to observe <strong>NSManagedObjectContextObjectsDidChangeNotification</strong>. This notification is posted when values of properties for managed objects in context are changed. The <em>userInfo</em> dictionary contains the following keys: <strong>NSInsertedObjectsKey</strong>, <strong>NSUpdatedObjectsKey</strong>, and <strong>NSDeletedObjectsKey, NSRefreshedObjectsKey</strong>. If are already familiar with this, you can take a look on our wrapper which <strong>can save you</strong> from writing <strong>boilerplate code. </strong>I made gist with source code which you can find below the article and also <a href="https://gist.github.com/m1entus/22ce2149233c4799a4aea856f520564a">here</a>. This is how the interface for our observer look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c0a2c198065459c12cd7eff2f9740ce/href">https://medium.com/media/9c0a2c198065459c12cd7eff2f9740ce/href</a></iframe><p>It is very easy to use, all you need is to create instance of <strong>CoreDataContextObserver </strong>and pass context which you want to observe:</p><pre>let context = NSManagedObjectContext.defaultContext<br>let observer = CoreDataContextObserver(context: context)</pre><p>Next, you need to pass <strong>NSManagedObject</strong> instance which you will observe, and if something have changed you will get information about it in completion handler:</p><pre>observer.observeObject(journal, completionBlock: { object, state in<br>    print(“CHANGED: \(object.changedValuesForCurrentEvent())\n”)<br>    print(“state: \(state)”)<br>})</pre><p><strong>CoreDataContextObserver</strong> is not limited to only one object, you can observe many objects for different state, for example if you want to know about journal deletion, you will observe .<em>Deleted</em> state:</p><pre>observer.observeObject(journal, state: .Deleted, completionBlock: { object, state in<br>    print(“OBJECT DELETED\n”)<br>})</pre><p>In this way you can in clean way track all changes on <strong>NSManagedObject</strong>. I have created <a href="https://github.com/inspace-io/ContextWatcher">example project</a> on our github where you can play with <strong>CoreDataContextObserver.</strong></p><p>I want to mention is that if you are using</p><pre>func mergeChangesFromContextDidSaveNotification(_ <em>notification</em>: NSNotification!)</pre><p>then you will get changes in <strong>NSRefreshedObjectsKey. </strong>So, if you want to subscribe to this event using our observer you will use:</p><pre>observer.observeObject(journal, state: .Refreshed, completionBlock: { object, state in<br>    print(“OBJECT REFRESHED”)<br>})</pre><p><em>If you found these resources helpful or you’re an awesome person hit the </em>💚<em>. Here you will find </em><a href="https://github.com/inspace-io/ContextWatcher"><em>example project</em></a><em> and below you will find full source code:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a634f74854a9476956d8c1398c25b52/href">https://medium.com/media/0a634f74854a9476956d8c1398c25b52/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f64532f36ef4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inspace-labs-blog/how-to-observe-changes-on-single-instance-of-nsmanagedobject-f64532f36ef4">How to observe changes on single instance of NSManagedObject</a> was originally published in <a href="https://medium.com/inspace-labs-blog">inspace labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient and bug-free fragment injection in Android MVP applications]]></title>
            <link>https://medium.com/inspace-labs-blog/efficient-and-bug-free-fragment-injection-in-android-mvp-applications-1245a3dd5a9?source=rss----51d2f60ae8f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/1245a3dd5a9</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[model-view-presenter]]></category>
            <dc:creator><![CDATA[Maksym Plencler]]></dc:creator>
            <pubDate>Mon, 11 Apr 2016 07:47:38 GMT</pubDate>
            <atom:updated>2016-04-11T07:47:38.574Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this article, we introduce a simple extension for base fragment interface that we use in Android applications with MVP architecture. In order to take advantage of Dependency Injection pattern we have to be aware of injected view’s lifecycle. We use that knowledge to write efficient and stable applications. The simple solution that we propose will protect your application from unwanted bugs without compromising its performance. After reading the article you will familiar with an interesting use case for testing your application.</em></p><h4>Introduction</h4><p>We emphasize on the quality of our solutions when crafting applications. That’s why we continue to improve the tools and guidelines that we use.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o85g6d5jshfIoiGaY%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2Fthumbs-up-john-travolta-american-crime-story-3o85g6d5jshfIoiGaY&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3o85g6d5jshfIoiGaY%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/03b6936496c9034613892592818d3de5/href">https://medium.com/media/03b6936496c9034613892592818d3de5/href</a></iframe><p>It has always been struggle for Android developers to find architecture for project that make the application easy to maintain and to test. Recently a concept of Model-View-Presenter (MVP) architecture has become very popular. You can find many sources that refers this architecture concept. We especially recommend the work of <a href="http://fernandocejas.com/">Fernando Cejas</a>, which became an inspiration for us, and to which we refer often.</p><p>One definition says that efficiency is about doing things in an optimal way. By using MVP architecture we are giving up some efficiency as we are putting extra effort to stick to the MVP guidelines. But we consider it an investment, and it pays off quickly. Dependency Injection (DI) is technology with many advantages and one of them is reducing the extra effort, so with DI, applying MVP to your project is not that expensive.</p><h4>The story</h4><p>Basically, every fragment in our application extends BaseFragment as it provides method for getting DI component. The component is responsible for injecting fields annotated with <em>@Inject</em> annotation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7461387270e19058218e4395fde8addf/href">https://medium.com/media/7461387270e19058218e4395fde8addf/href</a></iframe><p>As you can see fragment’s parent activity that implements <em>HasComponent</em> interface is an owner of the component. All we need to know is that the component is being initialized on activity’s <em>Activity.onCreate(Bundle</em>) callback.</p><p>Have a look on a gist of <em>SampleFragment</em> that extends <em>BaseFragment</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2800d574993a08371c9e1df81375499f/href">https://medium.com/media/2800d574993a08371c9e1df81375499f/href</a></iframe><p>The field injection is performed on <em>onActivityCreated(Bundle)</em>. This lifecycle callback tells the fragment that its activity has completed its own <em>Activity.onCreate()</em>. This sounds like good fit for referencing to activity’s fields from fragment context, isn’t it?</p><p>But is it efficient? By design, activity is destroyed and recreated on configuration changes (such as a change in screen orientation, language, etc). This means that <em>onActivityCreated(Bundle)</em> can be called multiple times during lifecycle of an injected fragment. This leads to the loss of state of any field injected previously. That’s bad if the state was result of any expensive operation (fetching data from server, etc). OK, we can fix that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/975e33bf05242c7758f55accac395894/href">https://medium.com/media/975e33bf05242c7758f55accac395894/href</a></iframe><p>Referencing DI component on <em>onCreate(Bundle)</em> is possible as we are creating and attaching fragment instances on <em>Activity.onCreate(Bundle)</em>. This is the easiest way to guarantee single fragment injection as <em>Fragment.onCreate(Bundle)</em> won’t be called on orientation changes.</p><h4>Bug hunting</h4><p>The problem is when the application stays in the background for a while and a recently displayed activity is recycled by Android. Bringing back the application causes <em>NullPointerException </em>(<em>NPE</em>)<em> </em>as the activity’s component is called by the fragment before it is initialized (both fragment and activity are recreated at the same time).</p><p>At first, the only way to reproduce this bug was to keep activity in background for a long time, or start multiple applications simultaneously hoping Android will destroy our application…</p><p><strong>Developers tips and tricks:</strong><br>But there’s an easy way to reproduce such scenario. <strong>To reproduce</strong>: switch ON <em>Don’t keep activities</em> under <em>Apps</em> in <em>Settings/Developer</em> options. This will destroy every activity as soon as the user leaves it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*m8xhkM8EaxRity6QR84Jyw.png" /></figure><p>This way we were able to look into logs to find out what caused <em>NPE</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F10ttqzrQQODtUk%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2Fbatman-arkham-knight-10ttqzrQQODtUk&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F10ttqzrQQODtUk%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/1778d2fd4ddb9b586a4dc827eac5b192/href">https://medium.com/media/1778d2fd4ddb9b586a4dc827eac5b192/href</a></iframe><h4>Solution</h4><p>The solution is very simple as I mentioned early in the article.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9a92b5f6fc5e1001f6633f1b804a0f2/href">https://medium.com/media/d9a92b5f6fc5e1001f6633f1b804a0f2/href</a></iframe><p>We’ve introduced two lifecycle methods in <em>BaseFragment</em> class.</p><ol><li><strong><em>onInjectView()</em></strong> — called to do an optional injection on <em>onCreate(Bundle)</em> and if an exception is thrown or false returned, it is called on <em>onActivityCreated(Bundle)</em> again. Within this method you can get the injection component and inject the view. Retrun <strong>true</strong> if the injection was succesfull, then it will not be called again.</li><li>Based on returned value, the second method is called. The method is named <strong><em>onViewInjected(Bundle)</em></strong><em>,</em> as it is called only when the fragment has been injected and injected fields can be initialized.</li></ol><p><strong>Usage</strong> is simple like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a28992b5bac3b84028130d5221e0d4b8/href">https://medium.com/media/a28992b5bac3b84028130d5221e0d4b8/href</a></iframe><h4>Conclusion</h4><p>If you are using Dependency Injection in the similar way (and if you stick to MVP guidelines you probably do), the solution that we propose will protect your application from unwanted bugs without compromising its performance. I hope you will find this article useful.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxTiTnEx1hAntbgED9m%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2Fyou-da-real-mvp-xTiTnEx1hAntbgED9m&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxTiTnEx1hAntbgED9m%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="199" frameborder="0" scrolling="no"><a href="https://medium.com/media/aabf58630545673f5820db0823b88d06/href">https://medium.com/media/aabf58630545673f5820db0823b88d06/href</a></iframe><h4>References:</h4><p><a href="http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html">The Clean Architecture</a> by Uncle Bob<br><a href="http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/">Architecting Android…The clean way?</a> by Fernando Cejas</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1245a3dd5a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inspace-labs-blog/efficient-and-bug-free-fragment-injection-in-android-mvp-applications-1245a3dd5a9">Efficient and bug-free fragment injection in Android MVP applications</a> was originally published in <a href="https://medium.com/inspace-labs-blog">inspace labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[INSPhotoGallery — modern looking photo gallery written in Swift for iOS]]></title>
            <link>https://medium.com/inspace-labs-blog/insphotogallery-modern-looking-photo-gallery-written-in-swift-for-ios-7c6b3fdf54da?source=rss----51d2f60ae8f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/7c6b3fdf54da</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Michał Zaborowski]]></dc:creator>
            <pubDate>Tue, 05 Apr 2016 10:24:42 GMT</pubDate>
            <atom:updated>2016-04-05T10:24:42.136Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>INSPhotoGallery</em></strong> is a modern looking photo gallery written in Swift for iOS. It can handle downloading of photos but in addition to that it allows you to make custom logic for downloading images, also it allows you to make custom overlay if you won’t like current design. Also it supports interactive flick to dismiss, animated zooming presentation and many more. It was inspired by <a href="https://github.com/NYTimes/NYTPhotoViewer">NYTPhotoViewer</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*VPb0dwhQ8eaXSocMhznqCQ.gif" /></figure><p><strong><em>INSPhotoGallery</em></strong> is using standard UIKit components. It is build on <strong><em>UIPageViewController</em></strong> for swiping between photos, and <strong><em>UIScrollView</em></strong> for image zooming. In addition to that it support custom overlay view by implementing <strong><em>INSPhotosOverlayViewable </em></strong>protocol.</p><p>The reason why we wrote this library, is that there is no well written lightweight alternative photo gallery in Swift, which allows you to customize and manage downloading images using custom code.</p><h3>Usage</h3><p>The usage is very simple and comes down to a few lines. To present gallery you can use build-in <strong><em>INSPhoto </em></strong>class<strong><em> </em></strong>which implements <strong><em>INSPhotoViewable </em></strong>protocol and supports downloading images from <strong><em>NSURL</em></strong> using <strong><em>NSURLSession</em></strong>. Optionally you can implement <strong><em>INSPhotoViewable </em></strong>to your custom class and then present it.</p><pre>lazy var photos: [INSPhotoViewable] = {<br>   return [<br>      INSPhoto(imageURL: ..., thumbnailImage: ...),<br>      INSPhoto(imageURL: ..., thumbnailImage: ...)<br>   ]<br>}()</pre><p>In this case I will be presenting gallery after clicking on the <strong>cell</strong>, and I will use animated zoom animation. Addition to that Iwill pass all photos to allow user to swipe and switch between them. Using build-in handlers it is very easy to do it, all you need to do is pass initial <strong><em>referenceView </em></strong>and for dismissing view controller you need to implement <strong><em>referenceViewForPhotoWhenDismissingHandler </em></strong><em>to point a view where animation will end.</em></p><pre>func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {</pre><pre>   let <strong>cell</strong> = collectionView.cellForItemAtIndexPath(indexPath) as! ExampleCollectionViewCell<br>   let currentPhoto = photos[indexPath.row]<br>   let galleryPreview = INSPhotosViewController(photos: photos, initialPhoto: currentPhoto, <strong>referenceView</strong>: cell)</pre><pre>   galleryPreview.<strong>referenceViewForPhotoWhenDismissingHandler</strong> = { [weak self] photo in</pre><pre>      if let index = self?.photos.indexOf({$0 === photo}) {<br>         let indexPath = NSIndexPath(forItem: index, inSection: 0)<br>         return collectionView.cellForItemAtIndexPath(indexPath) as? ExampleCollectionViewCell<br>      }<br>      return nil<br>   }<br>   presentViewController(galleryPreview, animated: true, completion: nil)<br>}</pre><h3>Custom Photo Model</h3><p>Let assume the case where you have your own <strong><em>CustomPhoto</em></strong> model and you won’t use build-in type <strong><em>INSPhoto</em></strong>, but pass array of your photo objects directly to gallery. One of the reason why you would like to do this is that you would like use some library for downloading and caching photos or you have <strong><em>NSManagedObject</em></strong> model subclass and you would like to fetch images from database rather that downloading from internet or even you would like to display images from <a href="https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAsset_Class/">PHAsset</a> from <a href="https://developer.apple.com/library/ios/documentation/Photos/Reference/Photos_Framework/index.html#//apple_ref/doc/uid/TP40014408">Photos framework</a>. All you need is implement protocol <strong><em>INSPhotoViewable</em></strong> to your <strong><em>CustomPhoto</em></strong> model and thats it!</p><pre>public protocol INSPhotoViewable: class {<br>   var image: UIImage? { get }<br>   var thumbnailImage: UIImage? { get }</pre><pre>   func loadImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -&gt; ())<br>   func loadThumbnailImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -&gt; ())</pre><pre>   var attributedTitle: NSAttributedString? { get }<br>}</pre><p>This is how sample implementation will look like using <a href="https://github.com/Haneke/HanekeSwift">HanekeSwift</a> for downloading and caching images.</p><pre>class CustomPhotoModel: NSObject, INSPhotoViewable {<br>   var image: UIImage?<br>   var thumbnailImage: UIImage?</pre><pre>   var imageURL: NSURL?<br>   var thumbnailImageURL: NSURL?<br>   <br>   var attributedTitle: NSAttributedString?</pre><pre>   func loadImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -&gt; ()) {</pre><pre>      if let url = imageURL {<br>         Shared.imageCache.fetch(URL: url).onSuccess({ image in<br>            completion(image: image, error: nil)<br>         }).onFailure({ error in<br>            completion(image: nil, error: error)<br>         })<br>      } else {<br>          completion(image: nil, error: NSError(domain: “PhotoDomain”, code: -1, userInfo: [ NSLocalizedDescriptionKey: “Couldn’t load image”]))<br>      }<br>}</pre><p>There is nothing more to say, we hope this post was helpful and that <strong><em>INSPhotoGallery</em></strong> will help you building great apps. Example and source code is available in our <a href="https://github.com/inspace-io/INSPhotoGallery">GitHub repositery here!</a> — enjoy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c6b3fdf54da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inspace-labs-blog/insphotogallery-modern-looking-photo-gallery-written-in-swift-for-ios-7c6b3fdf54da">INSPhotoGallery — modern looking photo gallery written in Swift for iOS</a> was originally published in <a href="https://medium.com/inspace-labs-blog">inspace labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>