Slide 1

Slide 1 text

PLUG-IN ARCHITECTURE PATTERN WITH SWIFT 11° COCOAHEADS FORTALEZA

Slide 2

Slide 2 text

WHO AM I?

Slide 3

Slide 3 text

Bruno Macabeus macabeus

Slide 4

Slide 4 text

WHY SHOULD I USE PLUGIN ARCHITECTURE?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

It's open! (๑>◡<๑) https://github.com/stalkr-io http://getstal.kr

Slide 8

Slide 8 text

HOW PLUGIN ARCHITECT WORK?

Slide 9

Slide 9 text

Also called as “microkernel architecture” Source: www.oreilly.com/ideas/software-architecture-patterns/page/4/microkernel-architecture

Slide 10

Slide 10 text

BRIEF EXAMPLE WITH PYTHON

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

pyCertificate/ main.py plugin/ Certificado.py - loads the plugins - base class Certificado, with abstract attributes

Slide 18

Slide 18 text

assinaturas/ plugin/ alynne.py edson.py certificado/ CertificadoEventoPalestrante.py CertificadoEventoOuvinte.py logo/ ifce.py

Slide 19

Slide 19 text

Going go to PyCharm

Slide 20

Slide 20 text

NOW… HOW TO MAKE IT WITH SWIFT?

Slide 21

Slide 21 text

HEY… ONE LITTLE ADVICE

Slide 22

Slide 22 text

WARNING Everything here is experiments!!

Slide 23

Slide 23 text

USEFUL but, it is…

Slide 24

Slide 24 text

MY ATTEMPTS - DYLIB - BUNDLES

Slide 25

Slide 25 text

ST 1 ATTEMPT DYNAMIC LIBRARIES

Slide 26

Slide 26 text

Dynamic libraries: a.k.a dynamic shared libraries, shared objects, or dynamically linked libraries O que por nesse slide???

Slide 27

Slide 27 text

App using static libraries Source: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/OverviewOfDynamicLibraries.html

Slide 28

Slide 28 text

App using dynamic libraries Source: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/OverviewOfDynamicLibraries.html

Slide 29

Slide 29 text

Create a new dylib in Swift

Slide 30

Slide 30 text

Use your dylib with Swift

Slide 31

Slide 31 text

Eeeeh! It’s work!!

Slide 32

Slide 32 text

NO It’s not work in iOS/ tvOS

Slide 33

Slide 33 text

I sent a e-mail for Apple Engineer support: I want to compile a dynamic library to use in my apple tv's application. My dylib is wrote with Swift. I tried (see "Steps to Reproduce" section), but I can't load my dylib neither at simulator nor at physical device. Then I received: Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.

Slide 34

Slide 34 text

2 ATTEMPT BUNDLES ND

Slide 35

Slide 35 text

Ohh! I found a Apple’s documentation with a suggestive name and, this documentation explain about “Bundle”… but… what is it?

Slide 36

Slide 36 text

Bundles provide a interface to encapsulate executable (dylib, for example) and the resources (xib, for example). Source: https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html

Slide 37

Slide 37 text

Somebody make this things to iOS? Or with Swift? Yes! Somebody make it work in iOS! So so… Somebody make it work with Swift + Objc-C

Slide 38

Slide 38 text

Then… I created a Proof of Concept purely in Swift with a app to iOS, to send a AppStore

Slide 39

Slide 39 text

Eeeeh! It’s work!!

Slide 40

Slide 40 text

NO I can’t send it to AppStore

Slide 41

Slide 41 text

For some reasons, I can’t send it to AppStore - problem in certificate in bundle - size of app - and others random problems

Slide 42

Slide 42 text

BUT… THE MAJOR PROBLEM IS…

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

OTHER EXPERIMENTS - SCRIPT - LLVM C API

Slide 46

Slide 46 text

1 EXPERIMENT SCRIPT ST

Slide 47

Slide 47 text

Maybe another strategy is using not compiled code, but yes a script to download and execute in run time!

Slide 48

Slide 48 text

With JS, we have a proof of concept to run JS in AppleTV

Slide 49

Slide 49 text

2 EXPERIMENT LLVM C API ND

Slide 50

Slide 50 text

What is LLVM? Well… LLVM is “Low Level Virtual Machine”, and it’s not only one virtual machine Source: http://aosabook.org/en/llvm.html

Slide 51

Slide 51 text

Example of C code to LLVM IR C LLVM IR Source: http://aosabook.org/en/llvm.html

Slide 52

Slide 52 text

Then, Alex Desinov created a example of using LLVM C API with Swift

Slide 53

Slide 53 text

WORKAROUND…

Slide 54

Slide 54 text

Well… We can use a simple workaround… We could make the app 100% open source and, if the user wants create a plugin, he will need create a new file in the project. Some tools, like Fastlane, can help

Slide 55

Slide 55 text

Create a reflexive code can help… READ IT IN MY BLOG!! macalogs.com.br

Slide 56

Slide 56 text

SOME OTHERS THINGS…

Slide 57

Slide 57 text

Like Apple kill the dlopen in NSUserDefault, him can kill others solutions that appear. Apple has been closing any way to create a app can execute arbitrary code, even with respondsToSelector and performSelector

Slide 58

Slide 58 text

ABI

Slide 59

Slide 59 text

LITERATURE

Slide 60

Slide 60 text

http://aosabook.org/en/

Slide 61

Slide 61 text

https://www.oreilly.com/ideas/software-architecture-patterns