How to enhance your apps with scripting

The iOS platform provides, since iOS7, the JavaScriptCore framework, a way to use the WebKit javascript engine embedded on our apps. You can use it independently of a web view, what makes it a useful component when you new to flexibilize a feature or set of features.

Note: All code presented here was run in a Swift Playground (XCode 12.1).

The Basics

Let's start with the basics given through the following code:

The journey of a Feed Forward Network

Photo by Matt Howard on Unsplash

There are a lot of tutorials about how to create Feed Forward Networks in Keras, there are also a lot of tutorials on how to use convert an Image Classifier using convolutional network from Keras to CoreML using coremltools. But unfortunately when trying to create a Feed Forward Network on Keras, convert it to CoreML and then use the resulting model on an iOS application I could not find a good reference. After gathering parts from here and there, it was possible to make it work. …

Make cleaner and clearer asynchronous code in Swift

Promises are data structures that promise you a value of a given type when it is ready and let you handle this result. It makes easy to handle success and error as well as chaining and synchronizing asynchronous processes.

This is not a recent concept, as promises were proposed in 1976 by Daniel P. Friedman and David Wise. Similar concepts as eventual and future were proposed by Peter Hibbard also in 1976 and Henry Baker and Carl Hewitt in 1977. This concept is used in several concurrent programming languages.

There is a framework for promises in iOS called PromiseKit that…

A practical example

To conclude my monad series of posts, here is a practical example that I hope helps to make thinks clearer. If you have not seen this post you can check it here and here, or start by a specific post here.

The basic examples of monads in Swift are usually Arrays and Optionals. I thought about using a different one: a way to isolate the boilerplate code we use for asynchronous calls in Swift, that I check after its development that are very close to the concept of Promises

A promise represents an eventual completion, or error, of an asynchronous…


We, Swift programmers, are in touch and use some monads without even know that they are classified as such: Arrays (as well as all other Sequences) and Optionals are both valid examples for this statement.

There are also frameworks that implement other monads: RxSwift, a reactive programming framework implements Subjects (objects that can be observed and observe at the same time) as those.

They are even more useful in pure functional languages in order to deal specially with controlled side-effects. Chris Smith in this post describe four very important of them, the "Four Horsemen of Catapocalypse":

  • Failure — a function…

for Swift programmers

Photo by Jeff — CC BY-SA 2.0


Functors and monads are concepts that everyone who starts studying functional programming, sooner or later, gets in touch and usually has a hard time struggling with them.

Monad is a simple concept: it has a concise and direct definition. On the other hand, this definition is based on several layers of abstraction, what makes it hard to grasp. We can consider that monads are simple (in contrast to complex), but learning monads is usually difficult (in contrast to easy) for most people. To understand its full application and generality is one of the most hard things about it.

This could…

Sergio Ordine

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store