Isolating DB layer dependency for a better app architecture: a use case with Realm

If you are an iOS developer and you haven’t been hidden in the middle of nowhere for the last three years, you should know what Realm is: basically it’s an awesome dependency to you app.

We have seen during the latest years that other dependencies that helped a lot of people to build thousand of apps have been shut down. Yes I’m referring to Parse.

So I’m going to use Realm for my latest side project but the main goal for me now is to completely (or as much as possible) isolate the persistence layer from it’s concrete implementation (yes, you know, SOLID is just around the corner).

The first goal of introducing a new layer like this one is that any client would be able to program to an interface without caring at all about the persistence layer implementation. Another reason is that you could easily change database implementation or the persistence layer without affeting the rest of the codebase.

Continue Reading

CoreNFC tutorial

Well, when Apple presented iBeacon during the WWDC 2013, I bet that one year later they would have presented the NFC support. But it’s well known that I’m a terrible punter and Apple has finally introduce the support to NFC this year.

This means that starting from iOS 11 (and on iPhone 7/iPhone7+ and future deveices) our apps can leverage on NFC tags to get contextual info about the physical world around the user (especially for location aware apps, physical marketing campaigns, ..).

As described in the documentation:

Using Core NFC, you can read Near Field Communication (NFC) tags of types 1 through 5 that contain data in the NFC Data Exchange Format (NDEF)

So this means that so far it’s not possible to write NFC tags or card emulation.

NDEF

NDEF (NFC Data Exchange Format) is a protocol provided by the NFC Forum which is used to describe how a NFC tag must expose data. Every NDEF record is made up by two components:

  1. A record type (check out this doc)
  2. Payload data

Once a device (i.e. an iPhone or an Apple Watch) is ready to read data from a NFC tag and it’s placed near the tag, these components are exchanged between the NFC tag and the reader.

CoreNFC is able to interact with NFC tags 1/2/3/4 and 5.

Unfortunately this format is not fully supported because it seems that records like Mime type or URI are not included in the framework (or maybe we have to create custom classes to support them? 🤔)

Continue Reading

UITests: app resume from background thanks to Siri

This is a quick post about a new feature added by Apple in Xcode8.3 that let me test an edge case through UITests.

The problem

Let’s consider to have a business logic only applied when the app is resumed from background. And let’s say that if the app is resumed from background then your app navigation changes due to your business logic.

Until XCode8.2 every time a new UITest is executed, the app process is killed and the app is executed from scratch.

Browsing the Apple doc I’ve noticed that they have added the access to Siri through XCUIDevice and the only method exposed by it is:

XCUIDevice.shared().siriService.activate(voiceRecognitionText: "")

This let me to simulate the flow in which the user puts the app in background (using the Home button) and then resumes the app using Siri.

Continue Reading

Functional Lenses: an exploration in Swift

The context

The last feature I have implemented on the NowTV app is a cache that stores a complex data structure, basically a subset of a JSON response containing multiple and nested models.

This JSON is in translated in something like

Lately I’m studying the theory behind the Functional Programming and I was wondering how to access/update data stored in the cache in a functional way. Thanks to manub I ended up in Lenses and even though I’m not expert at all about FP, the aim of this post is just to share what I learned, from a lens newbie perspective 🙂

Continue Reading