From 8ff0583c74b8ac59d3d8c6eeaec480b4977c3f4a Mon Sep 17 00:00:00 2001 From: Moksh Pathak Date: Wed, 20 Apr 2022 19:20:26 +0530 Subject: [PATCH] docs: add swift guide Signed-off-by: Moksh Pathak --- docs/WebAssembly/Swift.md | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 docs/WebAssembly/Swift.md diff --git a/docs/WebAssembly/Swift.md b/docs/WebAssembly/Swift.md new file mode 100644 index 000000000..f28365ad0 --- /dev/null +++ b/docs/WebAssembly/Swift.md @@ -0,0 +1,87 @@ +# WebAssembly with SwiftWasm + +1. Setting up the environment + + First, we need to pull the docker image and run it in an interactive mode; we would be accessing the container from its bash. To do the same, run the following command. + + ``` + docker run --rm -it ghcr.io/swiftwasm/swift:latest /bin/bash + ``` + + +2. Code + + To write the fibonacci code, we need to have a text editor in the container. For this demo, we would be using nano text editor. To install the same, follow the below instructions : + + 1. First, we need to run the `apt update` command in our container. + 2. To install nano text editor using apt, we need to run `apt install nano` + + With our text editor now installed in the container, lets make a swift file and write the fibonacci code in it. + + To make a new file, we would be using the `touch` command. + + ``` + touch fibonacci.swift + ``` + + To open the newly created file in nano text editor, we use this simple command. + + ``` + nano fibonacci.swift + ``` + + The fibonacci code in Swift is as follows : + + ``` + func fibonacci(n: Int) -> Int { + var a = 0 + var b = 1 + for _ in 0..