The things you need to consider before make your iOS / Mac functions run on AWS Lambda / Linux

Last year in 2020 Swift supported AWS lambda officially and apple made video on WWDC 2020 Swift works with AWS Lambda.

So with this news, we can try to move those function into AWS Lambda or maybe into a backend service, so those function is available for other to use it. Of course there will be some obstacles, what the thing we need to consider before make our swift code base support multi platform (iOS, Mac, Linux, android).

Currently on my working project, we have rich iOS app, by the mean of rich is all the functions for user is written in iOS swift, generating PDF, business validation, calculation, etc. It’s not most of mobile client-server application.

With that so many features not able to use by other platform and some function was really having big effort to made, it’s really wasteful to make same function with having same effort because it’s written for iOS and other platform.

Why not just make function on backend make it as REST API and let front end call the functions, this was capable if we force the users to always online, but our app is required the user to able to use the app on offline as well, this requirement made our app getting push far away from client-server app.

so lately with this announcement I have great effort to share with you guys, the experience of convert iOS library into AWS Lambda.

source: www.reddit.com
  1. See how spaghetti your code is?

if your code base doesn’t have clean layers, so many 3rd dependencies who not support linux, magic codes no one understand.

if your UIButton is written on the business logic, your core data is written in your domain class, this meaning your code base doesn’t have good layer separation you can refer to have clean architecture design.

in order to cope that you need to refactor to make all UI component stay on UIViewController or UIView class and all 3rd party is on the limited room, you can refer the proxy pattern to make your 3rd party only imported on one class, this one is the biggest obstacle because definitely there no UIKit on the linux, no core data as well because all of those is iOS library.

if you passed the first stage, you need to list down all 3rd parties and find out is that 3rd party is supported linux, not all 3rd party is linux friendly so if you not really find the library able to work for iOS and linux both, you can put condition in your code.

The sample above is for math library, Darwin is for apple platform and Glibc for linux.

Source: www.reddit.com

2. How good your unit test is?

If your project doesn’t have unit test this another problem after the project is success to compile.

you need to make sure that all codes is running well on linux environment, if you don’t have any unit test, you need to do manual test, when getting crash or exception this will hard to debug, because there is no clue of what is exactly the code cause crash.

So if you have proper unit test you can run that test on linux environment and see if there any failure cause by unfinished implementation on linux.

Please add on comment what do you think need consideration . Thanks

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