$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Overview of Swift and iOS App development
Search
asmz
July 05, 2019
Technology
0
1.3k
Overview of Swift and iOS App development
アプリ開発 - Swift編
Talked at 宮城アプリ開発勉強会 #1
asmz
July 05, 2019
Tweet
Share
More Decks by asmz
See All by asmz
Firebase App Testing Agentで始めるAIベースの柔軟なE2Eテスト
asmz
0
660
モバイルアプリ開発へE2Eテストを導入しよう
asmz
0
170
React Native+Expoで始めるWebフロント開発
asmz
0
530
UIデザインを考える全ての人たちに捧げる Apple Human Interface Guidelinesのススメ
asmz
1
2.5k
How to get mobile app logs using Firebase Crashlytics
asmz
0
890
OK Google, Deploy the iOS app
asmz
1
930
Cooperate with Adobe XD, Zeplin and Xcode
asmz
1
3.1k
phpconsen LT
asmz
0
770
SWWDC 39
asmz
1
270
Other Decks in Technology
See All in Technology
エンジニアとPMのドメイン知識の溝をなくす、 AIネイティブな開発プロセス
applism118
4
930
ガバメントクラウド利用システムのライフサイクルについて
techniczna
0
180
Snowflakeでデータ基盤を もう一度作り直すなら / rebuilding-data-platform-with-snowflake
pei0804
2
640
技術以外の世界に『越境』しエンジニアとして進化を遂げる 〜Kotlinへの愛とDevHRとしての挑戦を添えて〜
subroh0508
1
390
品質のための共通認識
kakehashi
PRO
3
220
Debugging Edge AI on Zephyr and Lessons Learned
iotengineer22
0
120
Reinforcement Fine-tuning 基礎〜実践まで
ch6noota
0
150
大企業でもできる!ボトムアップで拡大させるプラットフォームの作り方
findy_eventslides
1
550
直接メモリアクセス
koba789
0
280
小さな判断で育つ、大きな意思決定力 / 20251204 Takahiro Kinjo
shift_evolve
PRO
1
580
ML PM Talk #1 - ML PMの分類に関する考察
lycorptech_jp
PRO
1
720
20251209_WAKECareer_生成AIを活用した設計・開発プロセス
syobochim
5
1.4k
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Balancing Empowerment & Direction
lara
5
790
Fireside Chat
paigeccino
41
3.7k
How to Ace a Technical Interview
jacobian
280
24k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
It's Worth the Effort
3n
187
29k
Agile that works and the tools we love
rasmusluckow
331
21k
The Cult of Friendly URLs
andyhume
79
6.7k
Thoughts on Productivity
jonyablonski
73
5k
[SF Ruby Conf 2025] Rails X
palkan
0
490
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
4 Signs Your Business is Dying
shpigford
186
22k
Transcript
asmz.beer アプリ開発 - Swift編 2019/07/05 宮城アプリ開発勉強会 #1 Akira Shimizu /
asmz
asmz.beer 誰なのか? • Akira Shimizu / asmz (@_asmz) • https://asmz.beer/
• 株式会社ビデオマーケット 仙台オフィス • iOSエンジニア • 個人開発:IT勉強会検索アプリ ◦ https://eventech.asmz.beer/
asmz.beer 本日の内容 • ターゲット ◦ 他のプログラミング言語でアプリやWeb開発したことがあるけ ど、Swiftは使ったことがない人 • 目標 ◦
SwiftによるiOSアプリ開発の雰囲気を掴める ◦ Xcodeを起動して、試しにちょっとSwift触ってみる ◦ Mac買っちゃう
asmz.beer アジェンダ 1. Swift概要 2. Swift言語仕様 a. 基本的な構文 b. 特徴的な構文
3. SwiftによるiOSアプリ開発 4. Swiftまとめ、これから
asmz.beer 1. Swift概要
asmz.beer Swiftとは • 2014年にApple社が発表したプログラミング言語 • 各種Apple製品(iPhone, iPad, Apple TV, Apple
Watch, Mac)向けアプリケーションの開発が可能 • 2015年にオープンソース化 ◦ Linux上での動作サポート開始
asmz.beer Swiftとは • 過去の開発言語であるObjective-Cと互換 性を保ちながらも、クセの少ない記述方式 を実現 // Objective-C UITableView *myTableView
= [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; // Swift let myTableView = UITableView(frame: .zero, style: .grouped)
asmz.beer Swiftとは 2014/9/10 Swift 1.0 2015/9/21 Swift 2.0 - 多数の制御文
追加 - エラーハンドリ ング実装 - Protocol extension 2016/9/13 Swift 3.0 - 破壊的な仕様 変更 2017/9/19 Swift 4.0 - Stringや Dictionary型 強化 - Codable登場 1 2 3 4 2019/3/25 Swift 5.0 - ABI安定化 - Result型追加 5 2015/12/3 OSS化
asmz.beer 2. Swift言語仕様 a. 基本的な構文
asmz.beer 基本構文 // 型 let age: Int = 37 let
name: String = "asmz" let isMale: Bool = true let height: Double = 169.5 let pref = "Sendai" // 型推論 // 定数 let taro: String = "taro" let jiro = "jiro" jiro = "saburo" // Error // 変数 var person = "taro" person = "saburo" // ◦ • 静的型付け • 型推論 • 文末セミコロンなし
asmz.beer 基本構文 // if if age > 37 { print("年上!")
} // for-in let ages = [22, 35, 47] for age in ages { print("あなたは\(age)歳です") } // for-in + where let ages = [22, 35, 47] for age in ages where age > 37 { print("\(age)歳の人は年上!") } • if, for-in, switch, whileなど一般的な制 御構文が利用可 • 条件式カッコなし
asmz.beer 基本構文 // class class MyClass { func myMethod() {
… } } // struct struct MyStruct { let width: Int let height: Int } // protocol protocol MyProtocol { func protocolMethod() } • クラス • 構造体(struct) • インタフェース (protocol)
asmz.beer 2. Swift言語仕様 b. 特徴的な構文
asmz.beer Null安全(Optional型) var hoge: String = "abc" // 非Optional(nullを格納できない) var
fuga: String? = "abc" // Optional型(nullを格納できる) print(hoge) // abc print(fuga) // Optional(abc) hoge = nil // Compile Error! fuga = nil // OK • Null値を許容するかどうかコンパイラレベルで区別できる
asmz.beer Null安全 (Optional型) • Optional型の値を 参照する場合は Unwrapする • 強制的にUnwrap するときは注意
var fuga: String? = "abc" print(fuga) // Optional(abc) // if-letでUnwrap if let unwrapFuga = fuga { print(unwrapFuga) // abc } // ↑と同じ挙動になる if fuga != nil { // Force unwrap print(fuga!) // abc } fuga = nil print(fuga!) // クラッシュ(ぬるぽ)
asmz.beer 引数ラベル • 関数・メソッドの引数にラベルがある func logger(level: Level, message: String) {
... } logger(level: .fatal, message: "Fatal error!") // ラベル名と変数名を分けたい場合 func remove(at index: Int) { ... } remove(at: 5) // ラベル省略したい場合 func remove(_ element: Element) { ... } remove(someElement)
asmz.beer 引数ラベル • 英文としてスムーズに読めるように func insert(item: Item, position: Int) {
... } x.insert(item: y, position: z) // "x, insert item y position z" 詳しくはSwift API Design Guidelines(https://swift.org/documentation/api-design-guidelines/)参照 func insert(_ item: Item, at position: Int) { ... } x.insert(y, at: z) // "x, insert y at z" Swifty!
asmz.beer 3. SwiftによるiOSアプリ開発
asmz.beer iOSアプリ開発環境 • 統合開発環境「Xcode」を使用 ◦ テキストエディタ ◦ コード補完 ◦ UI設計ツール
(Interface Builder) ◦ デバッグツール群 ◦ シミュレータ ◦ テスト実行
asmz.beer
asmz.beer 主要なFramework • Foundation ◦ 主要なデータ型、コレクションの定義、データ永続化、日付や時 刻の計算、ネットワーキング、Operating System Serviceへの アクセスなど、アプリ動作の基盤となるFramework
• UIKit ◦ iOS / tvOSでグラフィカルなイベント駆動型UI機能を提供する Framework
asmz.beer UIKit • UIWindowクラス ◦ アプリ全体の画面土台 • UIViewControllerクラス ◦ 画面の表示と各種イベント
・ライフサイクル管理 • UIView(とそのサブクラス) ◦ 画面各部品の表示と管理 UIViewController UIBarButtonItem UIButton UITextField UILabel UITableView UIViewの サブクラス
asmz.beer UIKitを用いたアプリ画面開発 • Xcodeで画面設計 ◦ 実体はXML • 画面とソースを紐づけ て、ロジックを実装 ViewController
asmz.beer UIKitを用いたアプリ画面開発 • Swiftでもレイアウト実装は可能だが、プレビューできない let label = UILabel(frame: .zero) label.text
= "Text from code" label.textColor = .red view.addSubview(label) // 画面サイズに合わせるための自動レイアウトルールを設定 label.translatesAutoresizingMaskIntoConstraints = false label.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true label.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
asmz.beer SwiftUI • UIKitに代わる新たなUIフレームワーク ◦ Swiftでレイアウト実装が可能になる ◦ UIKitはObj-Cベース、SwiftUIはAll Swift •
POINT ◦ 宣言的な画面レイアウトコーディング ◦ 視覚的なUIデザインツールと統合 ◦ リアルタイムプレビュー
asmz.beer refs: https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
asmz.beer 4. Swiftまとめ、これから
asmz.beer まとめ • Swiftは、記述にクセが少なく学習コストは少ないにも関 わらず、モダンな技術・機能が取り入れられているプロ グラミング言語 • オープンソース化されてはいるものの、クロスプラット フォーム対応の盛り上がりはあまりなく、現状は「Apple 製品用」プログラミング言語
asmz.beer Swiftのこれから • SwiftUIの発表で、古いObj-Cとの依存関係を減らして、 よりSwiftを進化させようというAppleの意気込みが感じ られた • 東京のiOS Developer界隈も先日のWWDC絡みの勉 強会が連日開催されている模様
今後もSwiftは「Apple中心」に盛り上がっていくでしょう
asmz.beer Enjoy, App Engineering! 2019/07/05 宮城アプリ開発勉強会 #1 Akira Shimizu /
asmz
asmz.beer [PR] 公式動画配信サービス MIRAIL(ミレール) https://mirail.video/ 映画・ドラマ・アニメなどの映像作品を保有する「コンテンツホルダー」が、直接動 画を販売・配信することができる動画配信プラットフォーム