Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Tunnel 社内勉強会 Swift の紹介
Search
Motoi Washida
August 03, 2016
Programming
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Tunnel 社内勉強会 Swift の紹介
Motoi Washida
August 03, 2016
Transcript
122 slides
Swift の紹介 鷲田 基
始まり
2014 年 6 月
Apple WWDC で発表
(当時発表された) 特徴
モダン
安全
インタラクティブ
逆に言うと
Objective-C
古臭い
壊れやすい
手軽に試せない
質問
• Swift 使った事ある人いますか? • Objective-C 使った事ある人いますか? • Objective-C のコード見た事ある人いますか?
最初どう思いました?
None
Swift のモダンな所
1. 親しみやすい 2. 今時の機能
親しみやすい
Objective-C
Swift
親しみやすい
Objective-C からすると • API 呼び出し可能(相互で) • 似たようなオブジェクト指向の機能 ◦ Protocol、Protocol Extension(Category)
• ARC
Java
Swift
親しみやすい
Java からすると • 安全さ ◦ 静的型付け、ジェネリクス、アクセスコントロール、例外処 理 • (そもそもObjective-C と
Java はかなり近い)
LLからすると • 簡易な記述 ◦ 変数の省略(型推論)、高機能なコレクション処理 ◦ 配列、マップ、関数オブジェクトのリテラル • インタラクティブな環境(Playground)
静的型付け・オブジェクト指向を 基盤にしつつ LL の利便性や関数型言語の 手法を取り入れた
今時の言語
Scala や Kotlin, Go が近い
• 若干不便 • 低レベルの動作が推測しやすい ただし GC が無い
Swift の安全な所
Java と類似の安全性担保の機能 • 静的型付け、ジェネリクス • アクセスコントロール • 例外処理(チェック例外など)
他にもたくさん
安全を担保する機能を どんどん使ってバグを 減らしましょう!
⚠ 安全じゃない物
その1
nil / null
ぬるぽ (^^)
nil かもしれない。ビルドできない
Optional にすればビルド可能
if let … で中身を安全に取り出す
guard let … で nil の場合に return
• Optional ◦ nil の可能性があるものと無い物をコンパイル時に区別 • if let … /
guard let … ◦ 安全に nil じゃないものを取り出す
⚠ 安全じゃない物
その2
キャスト
キャスト、危険!
as? で安全にキャスト
switch 文で複数の分岐をシンプルに
enum でより明白に
• 強制なキャスト(as!) とオプショナルな as? ◦ as? を使うのが推奨 • パターンマッチ •
Swift の enum はとても柔軟
⚠ 安全じゃない物
その3
変数 (var)
• var … 変数 • let … 定数、Java の final
定数 (let) を使いましょう
var はバグを作りやすい
for … in … でわかりやすいループ
map でループで使う var も削除
• なるべく var を使わない • 言語の機能を使うと var を使わずに済む事が多 い
⚠ 安全じゃない物
その4
class
class
struct
struct の class との違い • インスタンス変数やメソッド定義などは一緒 ◦ 継承できないなど、幾つかの制限がある • 代入に対して
ARC では無くコピーがされる ◦ 循環参照などの問題が無いので比較的安全
その他の機能
いろいろ
タプル, Protocol Extension, typedef
@noesape, @autoclosure など
略
コミュニティ
公式ページ swift.org
仕様の提案とディスカッショ ン
[email protected]
決まった事
github.com/apple/swift- evolution
新機能の提案やその議論が 見れる
swift-evolution での提案例
プラットフォーム
macOS / iOS
Linux
Server Side Swift など という事をやろうとしている 人達もいるらしい
Android, Windows
一応あるらしい
Swift の今後について
最近のニュース
http://qiita. com/mono0926/items/c51b74fae679e1e39d2 b
Swift 4 の開発ロードマップ 発表
2017 年秋 リリース予定
Swift 3 の(非互換な)仕様は 確定
Swift 3 の変更
Swift 2系と非互換!
中にはアグレッシブな 変更点も
for …; …; … { … } 構文禁止
++/-- 演算子禁止
多くは細かい構文の改善
おまけ Apple と開発言語
Objective-C
macOS の前身 NeXTSTEP の 開発用言語
C 言語の Smalltalk 風オブジェクト指向 拡張
C 言語とオブジェクト指向 の部分が分離
[object method: arg]
@interface … @end
最小限の修正で最大限の機 能の提供
Java
Apple は Java が好き?
Objective-C の Java 風の 「Modern syntax」の検討 (1997)
やめた
Mac OS X 発表 Cocoa が Java で書けた (2000)
10.4 でサポート外に
Java を Apple が独自提供
Oracle が提供する事に (いつかは忘れた)
いまいちモダンじゃない Objective-C
Java に対する期待は 一定数あった
しかし実現せず
最終的に独自言語 Swift を 開発する事に
結果として 今時かつ安全 ハイパフォーマンスな 期待感の高い言語に
以上です
More Decks by Motoi Washida
See All by Motoi Washida
CLIPでマルチモーダル画像検索 →とても良い
wm3
3
1.2k
アプリのための「レイヤー化」アーキテクチャ / Droid Meetup 2019-03
wm3
0
2.6k
Material Design の社内勉強会を行った / Android Engineer Design 1
wm3
1
220
API仕様書から自前でコード生成して運用した話 / DroidKaigi 2018 Reject Conference
wm3
0
960
apply() 要らなくない?
wm3
2
1.6k
Firebase Analytics で 画像ロードのパフォーマンス を測定し、改善をした話
wm3
2
1.5k
iOS の Reactive 系ライブラリ
wm3
1
990
Other Decks in Programming
See All in Programming
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
250
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
310
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
ActionController meets Protocol Buffers
sorah
1
800
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
260
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
280
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
300
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
250
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
180
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
670
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Typedesign – Prime Four
hannesfritz
42
3.2k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
790
Docker and Python
trallard
47
4.3k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Writing Fast Ruby
sferik
630
63k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k