SlideShare a Scribd company logo
Swift 3.0 の新しい機能(のうちの9つ)



 

紙版は絶版、電⼦書籍は販売中
Swift 3.0 の新しい機能(のうちの9つ)


#cswift
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
:
@available(*, unavailable, renamed: "NewProtocol")
typealias PreviousProtocol = NewProtocol
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
renamed message
@swift3_migration(message: "MESSAGE")
func doSomething() { … }
@swift3_migration(renamed: "NewProtocol")
typealias PreviousProtocol = NewProtocol
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
if /* comment */!isValid { ... }
value +/* comment */coefficient
!
+/*
optionalArray/* Comment */?.count
value+/* comment */coefficient
?
+
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
!
let optionalValue: Int! = 100
var a: Int!
var b: Int?
// なぜか ImplicitlyUnwrappedOptional<Int> として認識
print(a.dynamicType)
// こちらは Optional<Int> 型として認識
print(b.dynamicType)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
func function(first: Int, second: Int, third: Int) {
}
function(first: 1, second: 10, third: 3)
_
// ラベル名を label にする
func function(label value: Int) {
}
func function(_ label value: Int) {
}
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
func function(@noescape f: () -> Int) {
}
func function(@autoclosure f: () -> Int) {
}
func function(f: @noescape () -> Int) {
}
func function(f: @autoclosure () -> Int) {
}
Swift 3.0 の新しい機能(のうちの9つ)
func function(f: () -> Int)
-> (@noescape (Int) -> Int) -> Int {
return { g in g(f()) }
}
func method() -> Int {
let g: @noescape (Int) -> Int = {
$0 + action() * 2
}
return function(g)
}
func method() -> Int {
func g(_ value: Int) -> Int {
return value + action() * 2
}
return function(g)
}
func function(@noescape f: () -> Int)
-> (@noescape (Int) -> Int) -> Int {
return { g in g(f()) }
}
func function(@noescape f: () -> Int)
-> @noescape (@noescape (Int) -> Int) -> Int {
return { g in g(f()) }
}
Swift 3.0 の新しい機能(のうちの9つ)
func function() -> (@autoclosure () -> Int) -> Int {
return { (f: @autoclosure () -> Int) in f() }
}
// 関数で得た、関数を取る関数に、値をそのまま渡せる
let f = function()
let result = f(100)
let f: () -> (@autoclosure () -> Int) -> Int = {
return { (f: @autoclosure () -> Int) in f() }
}
// 関数を取る関数に、値をそのまま渡せる
let result = f(100)
let value: @autoclosure () -> Int = {
return 100
}
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
func method(inout result: Int) {
}
func method(inOut result: Int) {
}


func method(result: inout Int) {
}
func method(inOut result: inout Int) {
}
func method(inout result: inout Int) {
}
func method(`inout` result: inout Int) {
}


func method(result: inout Int) {
}
func method(inOut result: inout Int) {
}
func function() -> (result: inout Int) -> Void {
return { (result: inout Int) -> Void in
result = 700
}
}
func function() -> (result: inout Int) -> Void {
return { $0 = 700 }
}
let f: (inout Int) -> Void = {
return { $0 = 5000 }
}
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
func freeFall(context: Context)(time: Double)
-> Double {
return -1 / 2 * time * time *
context.gravitationalAcceleration
}
func freeFall(context: Context)
-> (time: Double) -> Double {
return { time in
-1 / 2 * time * time *
context.gravitationalAcceleration
}
}
// コンテキストを固定し、その環境を前提に動く関数を定義
let earth = Context(identifier: "Earth",
gravitationalAcceleration: 9.80665)
let freeFallOnEarth: (time: Double) -> Double
= freeFall(context: earth)
// 汎用関数でスマートに捌く
let timeInterval
= stride(from: 0.0, through: 100.0, by: 1.0)
let locations = timeInterval.map(freeFallOnEarth)
func function(object: Object)(multiple: Int) -> Int {
let value = object.value
return value * multiple
}
do {
let f = function(Object(100))
print(f(multiple: 5))
}
func function(object:Object) -> (multiple:Int) -> Int {
let value = object.value
return { multiple in value * multiple }
}
do {
let f = function(Object(100))
print(f(multiple: 5))
}
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
func function(var initial value: Int, count: Int) -> Int {
(1 ..< count).forEach { _ in
value += value
}
return value
}
func function(var initial value: Int, count: Int) -> Int {
(1 ..< count).forEach { _ in
value += value
}
return value
}
var value = 10
let answer = function(initial: value, count: 5)
func function(initial value: inout Int, count: Int) {
(1 ..< count).forEach { _ in
value += value
}
}
var value = 10
function(initial: &value, count: 5)
func function(var initial value: Int, count: Int) -> Int {
// 即座に value に変更を仕掛けていける
(1 ..< count).forEach { _ in
value += value
}
return value
}
func function(initial value: Int, count: Int) -> Int {
// 編集できるように新しい可変値変数で受け直す
var value = value
(1 ..< count).forEach { _ in
value += value
}
return value
}
func function(initial value: Int, count: Int) -> Int {
return (1 ..< count).reduce(value) { value, _ in
value + value
}
}
func function(let initial value: Int, count: Int) -> Int {
return (1 ..< count).reduce(value) { value, _ in
value + value
}
}
// if var 構文で使用可能
if var value = optionalValue { … }
// while 構文で使用可能
while var value = iterator.next() { … }
// for 構文で使用可能
for var value in values { … }
// switch 構文で使用可能
switch optionalValue {
case .some(var value): …
case .none: …
}
// guard var 構文が使用可能
guard var value = optionalValue else {
fatalError()
}
// これ以降で可変値変数 value が使える
value += 200
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)

More Related Content

PDF
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
PDF
Swift で JavaScript 始めませんか? #iOSDC
PDF
03 function overloading
PPT
Lecture 11 - Functions
PPT
Lecture 14 - Scope Rules
PDF
MP in Clojure
PDF
11 2. variable-scope rule,-storage_class
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift で JavaScript 始めませんか? #iOSDC
03 function overloading
Lecture 11 - Functions
Lecture 14 - Scope Rules
MP in Clojure
11 2. variable-scope rule,-storage_class

What's hot (20)

PPTX
Functions in C
PPSX
Functions in c
PPTX
C Programming Language Part 6
PPTX
F# Presentation
PPTX
PHP function
PPT
Function overloading(C++)
PPT
Lecture 13 - Storage Classes
PPT
lets play with "c"..!!! :):)
PDF
ScalaFlavor4J
PPTX
Namespaces
PPT
Functions and pointers_unit_4
PPT
Php Chapter 1 Training
PDF
Swift Programming Language
PPTX
Functions
DOCX
Operators
PDF
Functions
PPT
Functions in c
PDF
The best of AltJava is Xtend
PPT
Functions in C
Functions in c
C Programming Language Part 6
F# Presentation
PHP function
Function overloading(C++)
Lecture 13 - Storage Classes
lets play with "c"..!!! :):)
ScalaFlavor4J
Namespaces
Functions and pointers_unit_4
Php Chapter 1 Training
Swift Programming Language
Functions
Operators
Functions
Functions in c
The best of AltJava is Xtend
Ad

Viewers also liked (20)

PDF
Swift 3.0 の新機能 - 追加・変更まわりだけ、ざっくり紹介 2 #devsap
PDF
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
PDF
Swift 3 で新しくなったところ - 表面から見えにくいところを中心に紹介 #ISAOcorp
PDF
Xcode 再入門「Xcode の検索機能」 #さいたまdev
PDF
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
PDF
はじめてのiOSアプリ開発 ①
PDF
TestFlightみたいなのを自作する
PDF
Xcodeとstoryboardのすごさを思い知る、ソースコードを書かないプログラミング
PDF
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
PDF
Swift を振り返ってみよう #cswift
PDF
yidev 第18回勉強会 「業務でSwiftで3ヶ月開発してきたので一旦振り返り」
PPTX
Git svnではじめる忍者のごとく潜むgit
PDF
How to handle bitcode
PPTX
Swift3とObjective-Cのブリッジでハマったこと
PDF
Swift Code in Swift - 2日間でゲームを作ってみた
PDF
Swift 2.0 で変わったところ「後編」 #cswift
PDF
㉚Xcodeを覚えよう!簡単なアプリを作ってみよう!
PDF
NS Prefix - そこから見渡す Swift 3 の景色 #startup_mobile
PDF
Carthageについて知りたいn個のこと
PDF
iPhone開発者初心者向け資料「XcodeのStoryboardで画面を作ろう!」
Swift 3.0 の新機能 - 追加・変更まわりだけ、ざっくり紹介 2 #devsap
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 で新しくなったところ - 表面から見えにくいところを中心に紹介 #ISAOcorp
Xcode 再入門「Xcode の検索機能」 #さいたまdev
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
はじめてのiOSアプリ開発 ①
TestFlightみたいなのを自作する
Xcodeとstoryboardのすごさを思い知る、ソースコードを書かないプログラミング
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
Swift を振り返ってみよう #cswift
yidev 第18回勉強会 「業務でSwiftで3ヶ月開発してきたので一旦振り返り」
Git svnではじめる忍者のごとく潜むgit
How to handle bitcode
Swift3とObjective-Cのブリッジでハマったこと
Swift Code in Swift - 2日間でゲームを作ってみた
Swift 2.0 で変わったところ「後編」 #cswift
㉚Xcodeを覚えよう!簡単なアプリを作ってみよう!
NS Prefix - そこから見渡す Swift 3 の景色 #startup_mobile
Carthageについて知りたいn個のこと
iPhone開発者初心者向け資料「XcodeのStoryboardで画面を作ろう!」
Ad

Similar to Swift 3.0 の新しい機能(のうちの9つ) (20)

PDF
Idioms in swift 2016 05c
PDF
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
PDF
Swiftの関数型っぽい部分
PDF
AnyObject – 自分が見落としていた、基本の話
PDF
NS Prefix 外伝 … Copy-On-Write #関モバ
PDF
A swift introduction to Swift
PDF
Pooya Khaloo Presentation on IWMC 2015
PDF
コード
PDF
Swiftをキめると 気持ちいい!
PDF
스위프트를 여행하는 히치하이커를 위한 스타일 안내
PDF
Friendly Functional Programming
PDF
Coding in Style
PDF
Swift 5.1 Language Guide Notes.pdf
PDF
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
PDF
20191116 custom operators in swift
PDF
Tech fest
PDF
Programming Language Swift Overview
PDF
Swift Programming Language
PDF
Swift - the future of iOS app development
PDF
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Idioms in swift 2016 05c
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
Swiftの関数型っぽい部分
AnyObject – 自分が見落としていた、基本の話
NS Prefix 外伝 … Copy-On-Write #関モバ
A swift introduction to Swift
Pooya Khaloo Presentation on IWMC 2015
コード
Swiftをキめると 気持ちいい!
스위프트를 여행하는 히치하이커를 위한 스타일 안내
Friendly Functional Programming
Coding in Style
Swift 5.1 Language Guide Notes.pdf
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
20191116 custom operators in swift
Tech fest
Programming Language Swift Overview
Swift Programming Language
Swift - the future of iOS app development
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기

More from Tomohiro Kumagai (20)

PDF
最近気づいた勉強法 — 勉強会開催の習慣化 #yumemi_grow
PDF
Swift 所有権 要諦 #ゆるちとせ
PDF
_Function Builders in Swift #love_swift
PDF
Property Wrappers の特徴を眺める #swiftzoomin
PDF
みんなで Swift 復習会 GO! in "Swift Days Fukuoka" – 12nd′ オープニング&資料
PDF
みんなで Swift 復習会
GO! in 札幌 – 10th′′
PDF
イニシャライザー Part 2.5 #hakataswift
PDF
ニコニコ超会議・文化の交差点 #techpub #ニコニコ超会議 #さくらシンデレラ
PDF
Swift クラスのイニシャライザー #devsap
PDF
iOSCon 2019 in London #ioscon #love_swift
PDF
Around the 変数 let #love_swift
PDF
もくもく執筆会 #技術同人誌再販Night
PDF
みんなで Swift 復習会 GO! in 岩手 – 9th′
PDF
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
PDF
みんなで Swift 復習会 GO! in 福岡 – 8th′ #minna_de_swift
PDF
Getting Started with Attending iOSCon in London 高画質・追記版 #love_swift #ioscon
PDF
みんなで Swift 復習会
GO! in 京都 – 6th′
PDF
みんなで Swift 復習会 GO! in 福岡 – 5th′
PDF
勉強会の東京外開催の気持ち #yuru_bounen2017
PDF
みんなで Swift 復習会 GO! in 福岡・発表資料
最近気づいた勉強法 — 勉強会開催の習慣化 #yumemi_grow
Swift 所有権 要諦 #ゆるちとせ
_Function Builders in Swift #love_swift
Property Wrappers の特徴を眺める #swiftzoomin
みんなで Swift 復習会 GO! in "Swift Days Fukuoka" – 12nd′ オープニング&資料
みんなで Swift 復習会
GO! in 札幌 – 10th′′
イニシャライザー Part 2.5 #hakataswift
ニコニコ超会議・文化の交差点 #techpub #ニコニコ超会議 #さくらシンデレラ
Swift クラスのイニシャライザー #devsap
iOSCon 2019 in London #ioscon #love_swift
Around the 変数 let #love_swift
もくもく執筆会 #技術同人誌再販Night
みんなで Swift 復習会 GO! in 岩手 – 9th′
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
みんなで Swift 復習会 GO! in 福岡 – 8th′ #minna_de_swift
Getting Started with Attending iOSCon in London 高画質・追記版 #love_swift #ioscon
みんなで Swift 復習会
GO! in 京都 – 6th′
みんなで Swift 復習会 GO! in 福岡 – 5th′
勉強会の東京外開催の気持ち #yuru_bounen2017
みんなで Swift 復習会 GO! in 福岡・発表資料

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Digital Strategies for Manufacturing Companies
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Introduction to Artificial Intelligence
PPTX
history of c programming in notes for students .pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
top salesforce developer skills in 2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How Creative Agencies Leverage Project Management Software.pdf
ISO 45001 Occupational Health and Safety Management System
Digital Strategies for Manufacturing Companies
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction to Artificial Intelligence
history of c programming in notes for students .pptx
Understanding Forklifts - TECH EHS Solution
top salesforce developer skills in 2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
L1 - Introduction to python Backend.pptx
Online Work Permit System for Fast Permit Processing
Upgrade and Innovation Strategies for SAP ERP Customers
ManageIQ - Sprint 268 Review - Slide Deck
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Adobe Illustrator 28.6 Crack My Vision of Vector Design

Swift 3.0 の新しい機能(のうちの9つ)