SlideShare a Scribd company logo








“Type systems are generally formulated as collections of rules
for checking the ‘consistency’ of programs.”

Benjamin C. Pierce
is, as?, as! (as )

$ swift
Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8
clang-703.0.30).
Type :help for assistance.
1> 1 is Any
$R0: Bool = true
2> 1 is AnyObject
$R1: Bool = false
3> import Foundation
4> 1 is Any
$R2: Bool = true
5> 1 is AnyObject
$R3: Bool = true // ???
is, as?, as! (as )

$ swift
Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8
clang-703.0.30).
Type :help for assistance.
1> [1] is [Any]
$R0: Bool = true
2> [1] is [AnyObject]
repl.swift:2:5: error: 'Bool' is not convertible to ‘[AnyObject]’ // ???
[1] is [AnyObject]
~~~~^~~~~~~~~~~~~~
2> import Foundation
3> [1] is [Any]
$R3: Bool = true
4> [1] is [AnyObject]
$R4: Bool = true


nil
nil
$ ghci
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
…
Prelude> let square x = x * x
Prelude> :info square
square :: Num a => a -> a
Prelude> square 10
100
expression statement
// Objective-C
NSMutableAttributedString *mutableAttributedString =
[[NSMutableAttributedString alloc] init];
// Swift
let mutableAttributedString = NSMutableAttributedString()
• 3: Int (default), IntXX, UIntXX,
Double, Float, …
• 3.14159: Double (default), Float, …
$ swift
Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8
clang-703.0.30).
Type :help for assistance.
1> let x1 = 3
x1: Int = 3 // inferred to be Int
2> let x2 = Double(3)
x2: Double = 3 // inferred to be Double
3> let x3: Double = 3
x3: Double = 3 // explicit type specified
4> let y1 = 3.14159
y1: Double = 3.1415899999999999 // inferred to be Double
5> let y2 = Float(3.14159)
y2: Float = 3.14159012 // inferred to be Float
6> let y3: Float = 3.14159
y3: Float = 3.14159012 // explicit type specified
import CoreGraphics
// func CGPointMake(_ x: CGFloat, _ y: CGFloat) -> CGPoint
let x = CGFloat(1.0 / 3) // 1 / 3 = 0(?), 1.0 / 3 = 0.333
let y = CGFloat(1.0 / 3) // 1.0 / 3: Double to CGFloat
let p = CGPointMake(x, y)
// CGFloat Swift
// “1 / 3” “CGFloat / CGFloat -> CGFloat”
// “1” “3” “CGFloat”
let p = CGPointMake(1 / 3, 1 / 3)
Swift Type System
Swift Type System

More Related Content

Viewers also liked

Objective-C のキャストと Swift の型変換を比べてみる #akibaswift
Objective-C のキャストと Swift の型変換を比べてみる #akibaswiftObjective-C のキャストと Swift の型変換を比べてみる #akibaswift
Objective-C のキャストと Swift の型変換を比べてみる #akibaswift
Tomohiro Kumagai
 
バ、バカな...!ハッカソンの中で成長しているだと...!?
バ、バカな...!ハッカソンの中で成長しているだと...!?バ、バカな...!ハッカソンの中で成長しているだと...!?
バ、バカな...!ハッカソンの中で成長しているだと...!?
Kenji Tanaka
 
AWS Cognitoを実際のアプリで導入してハマったこと
AWS Cognitoを実際のアプリで導入してハマったことAWS Cognitoを実際のアプリで導入してハマったこと
AWS Cognitoを実際のアプリで導入してハマったこと
洋一郎 櫻井
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDC
Tomohiro Kumagai
 
Unowned / Weak References with Closure
Unowned / Weak References with ClosureUnowned / Weak References with Closure
Unowned / Weak References with Closure
Naruki Chigira
 
iOSアプリ開発のCI環境 - Jenkins編 -
iOSアプリ開発のCI環境 - Jenkins編 -iOSアプリ開発のCI環境 - Jenkins編 -
iOSアプリ開発のCI環境 - Jenkins編 -
Toshiyuki Hirata
 
Xcodeの管理を楽に - Jenkins編 -
Xcodeの管理を楽に - Jenkins編 -Xcodeの管理を楽に - Jenkins編 -
Xcodeの管理を楽に - Jenkins編 -
Toshiyuki Hirata
 
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
Kenji Tanaka
 
Blending Culture in Twitter Client
Blending Culture in Twitter ClientBlending Culture in Twitter Client
Blending Culture in Twitter Client
Kenji Tanaka
 
Swift らしい表現を目指そう #eventdots
Swift らしい表現を目指そう #eventdotsSwift らしい表現を目指そう #eventdots
Swift らしい表現を目指そう #eventdots
Tomohiro Kumagai
 

Viewers also liked (10)

Objective-C のキャストと Swift の型変換を比べてみる #akibaswift
Objective-C のキャストと Swift の型変換を比べてみる #akibaswiftObjective-C のキャストと Swift の型変換を比べてみる #akibaswift
Objective-C のキャストと Swift の型変換を比べてみる #akibaswift
 
バ、バカな...!ハッカソンの中で成長しているだと...!?
バ、バカな...!ハッカソンの中で成長しているだと...!?バ、バカな...!ハッカソンの中で成長しているだと...!?
バ、バカな...!ハッカソンの中で成長しているだと...!?
 
AWS Cognitoを実際のアプリで導入してハマったこと
AWS Cognitoを実際のアプリで導入してハマったことAWS Cognitoを実際のアプリで導入してハマったこと
AWS Cognitoを実際のアプリで導入してハマったこと
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDC
 
Unowned / Weak References with Closure
Unowned / Weak References with ClosureUnowned / Weak References with Closure
Unowned / Weak References with Closure
 
iOSアプリ開発のCI環境 - Jenkins編 -
iOSアプリ開発のCI環境 - Jenkins編 -iOSアプリ開発のCI環境 - Jenkins編 -
iOSアプリ開発のCI環境 - Jenkins編 -
 
Xcodeの管理を楽に - Jenkins編 -
Xcodeの管理を楽に - Jenkins編 -Xcodeの管理を楽に - Jenkins編 -
Xcodeの管理を楽に - Jenkins編 -
 
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
VC「もしかして...」Model「私たち...」「「入れ替わってるー!?」」を前前前世から防ぐ方法
 
Blending Culture in Twitter Client
Blending Culture in Twitter ClientBlending Culture in Twitter Client
Blending Culture in Twitter Client
 
Swift らしい表現を目指そう #eventdots
Swift らしい表現を目指そう #eventdotsSwift らしい表現を目指そう #eventdots
Swift らしい表現を目指そう #eventdots
 

Similar to Swift Type System

Swift internals
Swift internalsSwift internals
Swift internals
Jung Kim
 
Chapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxChapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptx
SovannDoeur
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
Kaz Yoshikawa
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
Dierk König
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia
岳華 杜
 
BED-Con 2016 - I have a stream - Einsichten in Reactive Programming
BED-Con 2016 - I have a stream - Einsichten in Reactive ProgrammingBED-Con 2016 - I have a stream - Einsichten in Reactive Programming
BED-Con 2016 - I have a stream - Einsichten in Reactive Programming
Jan Carsten Lohmüller
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
Gyu-sun Youm
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
Gyu-sun Youm
 
Kotlin
KotlinKotlin
Kotlin
BoKaiRuan
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
Gyu-sun Youm
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015
Dierk König
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
Pofat Tseng
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
Visual Engineering
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School ProgrammersSiva Arunachalam
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
openak
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
Dean Hamstead
 
Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
Lennart Regebro
 

Similar to Swift Type System (20)

Swift internals
Swift internalsSwift internals
Swift internals
 
Chapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxChapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptx
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia
 
BED-Con 2016 - I have a stream - Einsichten in Reactive Programming
BED-Con 2016 - I have a stream - Einsichten in Reactive ProgrammingBED-Con 2016 - I have a stream - Einsichten in Reactive Programming
BED-Con 2016 - I have a stream - Einsichten in Reactive Programming
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
 
Kotlin
KotlinKotlin
Kotlin
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
 
Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Loops in Python.pptx
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 

More from Goichi Hirakawa

Strings and characters in swift
Strings and characters in swiftStrings and characters in swift
Strings and characters in swift
Goichi Hirakawa
 
WebKit Overview
WebKit OverviewWebKit Overview
WebKit Overview
Goichi Hirakawa
 
Server-side Swift
Server-side SwiftServer-side Swift
Server-side Swift
Goichi Hirakawa
 
Swift API Design Guidelines (dec 3, 2015)
Swift API Design Guidelines (dec 3, 2015)Swift API Design Guidelines (dec 3, 2015)
Swift API Design Guidelines (dec 3, 2015)
Goichi Hirakawa
 
New Objective-C Features for Swift 2.0
New Objective-C Features for Swift 2.0New Objective-C Features for Swift 2.0
New Objective-C Features for Swift 2.0
Goichi Hirakawa
 
Objective-C Generics
Objective-C GenericsObjective-C Generics
Objective-C Generics
Goichi Hirakawa
 
Objective-C Generics LT version
Objective-C Generics LT versionObjective-C Generics LT version
Objective-C Generics LT version
Goichi Hirakawa
 
Mix and Match / Swift and Objective-C
Mix and Match / Swift and Objective-CMix and Match / Swift and Objective-C
Mix and Match / Swift and Objective-C
Goichi Hirakawa
 
Strings and Characters in Swift
Strings and Characters in SwiftStrings and Characters in Swift
Strings and Characters in Swift
Goichi Hirakawa
 

More from Goichi Hirakawa (9)

Strings and characters in swift
Strings and characters in swiftStrings and characters in swift
Strings and characters in swift
 
WebKit Overview
WebKit OverviewWebKit Overview
WebKit Overview
 
Server-side Swift
Server-side SwiftServer-side Swift
Server-side Swift
 
Swift API Design Guidelines (dec 3, 2015)
Swift API Design Guidelines (dec 3, 2015)Swift API Design Guidelines (dec 3, 2015)
Swift API Design Guidelines (dec 3, 2015)
 
New Objective-C Features for Swift 2.0
New Objective-C Features for Swift 2.0New Objective-C Features for Swift 2.0
New Objective-C Features for Swift 2.0
 
Objective-C Generics
Objective-C GenericsObjective-C Generics
Objective-C Generics
 
Objective-C Generics LT version
Objective-C Generics LT versionObjective-C Generics LT version
Objective-C Generics LT version
 
Mix and Match / Swift and Objective-C
Mix and Match / Swift and Objective-CMix and Match / Swift and Objective-C
Mix and Match / Swift and Objective-C
 
Strings and Characters in Swift
Strings and Characters in SwiftStrings and Characters in Swift
Strings and Characters in Swift
 

Recently uploaded

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 

Swift Type System

  • 1.
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. “Type systems are generally formulated as collections of rules for checking the ‘consistency’ of programs.” Benjamin C. Pierce
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. is, as?, as! (as )
 $ swift Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance. 1> 1 is Any $R0: Bool = true 2> 1 is AnyObject $R1: Bool = false 3> import Foundation 4> 1 is Any $R2: Bool = true 5> 1 is AnyObject $R3: Bool = true // ???
  • 15. is, as?, as! (as )
 $ swift Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance. 1> [1] is [Any] $R0: Bool = true 2> [1] is [AnyObject] repl.swift:2:5: error: 'Bool' is not convertible to ‘[AnyObject]’ // ??? [1] is [AnyObject] ~~~~^~~~~~~~~~~~~~ 2> import Foundation 3> [1] is [Any] $R3: Bool = true 4> [1] is [AnyObject] $R4: Bool = true
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 22.
  • 23.
  • 24. $ ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help … Prelude> let square x = x * x Prelude> :info square square :: Num a => a -> a Prelude> square 10 100
  • 25. expression statement // Objective-C NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] init]; // Swift let mutableAttributedString = NSMutableAttributedString()
  • 26. • 3: Int (default), IntXX, UIntXX, Double, Float, … • 3.14159: Double (default), Float, …
  • 27. $ swift Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance. 1> let x1 = 3 x1: Int = 3 // inferred to be Int 2> let x2 = Double(3) x2: Double = 3 // inferred to be Double 3> let x3: Double = 3 x3: Double = 3 // explicit type specified 4> let y1 = 3.14159 y1: Double = 3.1415899999999999 // inferred to be Double 5> let y2 = Float(3.14159) y2: Float = 3.14159012 // inferred to be Float 6> let y3: Float = 3.14159 y3: Float = 3.14159012 // explicit type specified
  • 28. import CoreGraphics // func CGPointMake(_ x: CGFloat, _ y: CGFloat) -> CGPoint let x = CGFloat(1.0 / 3) // 1 / 3 = 0(?), 1.0 / 3 = 0.333 let y = CGFloat(1.0 / 3) // 1.0 / 3: Double to CGFloat let p = CGPointMake(x, y) // CGFloat Swift // “1 / 3” “CGFloat / CGFloat -> CGFloat” // “1” “3” “CGFloat” let p = CGPointMake(1 / 3, 1 / 3)