Giter Club home page Giter Club logo

20180915-swift-tour-slide's Introduction

% Swift Tour % ka % 2018-09-15

Author

ka

Gravatar

Website: kaosfield

Twitter: ka

GitHub: kaosf

License

CC BY-NC-SA 4.0

Copyright (C) 2018 ka

このページとリポジトリ

https://kaosf.github.io/20180915-swift-tour-slide

Repository: 20180915-swift-tour-slide - GitHub

Swift Tourに参加して

初Swiftです

今日の環境

Macbook持ってないので家でMac miniが動いててそれをリモートデスクトップで使う

つまりMac上で普通にスラスラ開発は出来ない

※今日この会場でMacじゃないの自分だけでは?

やるぞ!

一応LinuxでもSwiftのコンパイルは出来るらしいがつらそう

Swiftの利用目的が現状結局iOSアプリかMacアプリ

Swift PlaygroundsがインストールしようとしてもApp Store限定と言われて動かせん

グラフィカルなのやるには環境用意してるだけで時間かかりそうな気がする

そもそもSwift初心者だしと開き直って目標は低めに定める

RxSwiftを理解するとか出来たら良かったけど欲張らない

まずはSwiftに慣れよう

Optional型,パターンマッチ辺りのSwiftでの理解を自分に定着させよう

どうせCLIならUbuntuでやるだけでもいいかもしれん

Vimも使えるし

やるぞ!

$ sudo docker run -it ubuntu:16.04 bash

https://swift.org/download/#releases

を参考にしつつ…

# apt update
# apt -y upgrade
# apt install wget
# wget https://swift.org/builds/swift-4.1.3-release/ubuntu1604/swift-4.1.3-RELEASE/swift-4.1.3-RELEASE-ubuntu16.04.tar.gz

# tar xf swift-4.1.3-RELEASE-ubuntu16.04.tar.gz
# mv swift-4.1.3-RELEASE-ubuntu16.04/usr /usr/local/swift
# export PATH=/usr/local/swift/bin:$PATH

あかん

# swift --version
swift: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory

# apt search libatomic

とか探してみてそれらしいものを見つける

じゃあこれで

# apt install libatomic1

あかん(2nd)

# swift --version
swift: error while loading shared libraries: libedit.so.2: cannot open shared object file: No such file or directory

また探してみて以下で

# apt install libedit2

いけた!

# swift --version
Swift version 4.1.3 (swift-4.1.3-RELEASE)
Target: x86_64-unknown-linux-gnu

と思ったけどhelloworld.swiftを用意してみると…

あかん(3rd)

# swiftc -v helloworld.swift
...
<unknown>:0: error: link command failed with exit code 127 (use -v to see invocation)

clangやな

# apt install clang

いけた!!

# swiftc helloworld.swift

あかん(4th)

# ./helloworld
./helloworld: error while loading shared libraries: libicuuc.so.55: cannot open shared object file: No such file or directory

そしてとうとう本当に必要だったものを特定しました

(最後に必要だったのはlibicu55)

# apt -y install clang libatomic1 libedit2 libicu55

ここまでで参考にしたサイトなど

# echo 'print("Hello World!")' > helloworld.swift

# swift helloworld.swift
Hello World!

ここで気付く

( ˘⊖˘) 。o(まてよ、Swiftのコンテナイメージがそもそもあるんじゃ……?)

|DockerHub|┗(☋` )┓三

( ◠‿◠ )☛

▂▅▇█▓▒░(’ω’)░▒▓█▇▅▂ うわあああああぁぁぁぁぁぁぁ

はい

$ sudo docker run -it swift bash
# echo 'print("Hello World!")' > helloworld.swift
# swift helloworld.swift
Hello World!

まとめ

Dockerはべんり

おまけ

今日Swiftを試せるようになって書いた最大限のコード

```swift func f1(x: Int?) { if x == nil { print("nil") } else { // print(x) // BAD print(x!) // NOT GOOD } }

func f(_ x: Int?) { if let x = x { print(x) } else { print("nil") } }

func g(_ x: Int?) { switch x { case _?: print(x!) case nil: print("nil") } }

let foo: Int? = 1 f1(x: foo) f(foo) g(foo)

let bar: Int? = nil f1(x: bar) f(bar) g(bar)

</div>

#

Optional型とパターンマッチについて勉強出来たことが分かる

あと関数の引数に「外部引数名」という概念があることが分かった

#

<div style="text-align: center; margin-top: 25%; font-size: 200%">
Swift完全に理解した
</div>

#

おわり

20180915-swift-tour-slide's People

Contributors

kaosf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.