SlideShare une entreprise Scribd logo
1  sur  100
Télécharger pour lire hors ligne
CGFloat
2016/9/28 Hirohito Kato
• try! Swift 2016 

Swift (@RGfox)

• ( ) 

• CGFloat
• Swift
•
•
CGFloat
• Core Graphics
•
• SpriteKit/SceneKit UIKit
•
CGFloat
• double / float typedef
• CPU
• double
• CGFloat
• NSNumber CGFloat
• double
• iOS iPhone5 or iPhone5S 

…
double
20XX Swift
CGFloat
CGFloat ≠ Float
CGFloat ≠ Double
CGFloat “is” CGFloat
let value1: CGFloat = 240 // OK
let value1: CGFloat = 240 // OK
let value2: CGFloat = 80.0 // OK
let a = CGFloat(10)
let a = CGFloat(10)
let b = 30
let a = CGFloat(10)
let b = 30
let value = a + b // ERROR!
let a = CGFloat(10)
let b = 30
let value = a + b // ERROR!
let value = a + CGFloat(b) // OK
let pos = CGPoint(x: 160, y: 80.0)
let pos = CGPoint(x: 160, y: 80.0)
// OK
let pos = CGPoint(x: 160, y: 80.0)
// OK
let a = 160
let pos = CGPoint(x: 160, y: 80.0)
// OK
let a = 160
let pos = CGPoint(x: a, y: 80.0)
let pos = CGPoint(x: 160, y: 80.0)
// OK
let a = 160
let pos = CGPoint(x: a, y: 80.0)
// ERROR!
let pos = CGPoint(x: 160, y: 80.0)
// OK
let a = 160
let pos = CGPoint(x: a, y: 80.0)
// ERROR!
let x = 32
let x = 32
let y = 120.0
let x = 32
let y = 120.0
let w = Float(44.0)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
y: y,
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
y: y,
width: w,
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
y: y,
width: w,
height: h)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
y: y,
width: w,
height: h)
// ERROR!
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: x,
y: y,
width: w,
height: h)
// ERROR!
let x = 32
let x = 32
let y = 120.0
let x = 32
let y = 120.0
let w = Float(44.0)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
y: CGFloat(y),
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
y: CGFloat(y),
width: CGFloat(w),
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
y: CGFloat(y),
width: CGFloat(w),
height: h)
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
y: CGFloat(y),
width: CGFloat(w),
height: h)
// OK
let x = 32
let y = 120.0
let w = Float(44.0)
let h = CGFloat(24)
view.rect = CGRect(x: CGFloat(x),
y: CGFloat(y),
width: CGFloat(w),
height: h)
// OK
•
•
•
• Swift Objective-C
Float/Double CGFloat
•
•
• /
• …
CGFloat
Float Double =
…
extension Double {
var cgf:CGFloat { return CGFloat(self) }
}
let y = 1 + 10.0.cgf // OK, yay!
extension Double {
var cgf:CGFloat { return CGFloat(self) }
}
extension Int {
var cgf:CGFloat { return CGFloat(self) }
}
extension Float {
var cgf:CGFloat { return CGFloat(self) }
}
…
extension Double {
var c:CGFloat { return CGFloat(self) }
}
extension Int {
var c:CGFloat { return CGFloat(self) }
}
extension Float {
var c:CGFloat { return CGFloat(self) }
}
extension Float80 {
var c:CGFloat { return CGFloat(self) }
}
extension UInt {
var c:CGFloat { return CGFloat(self) }
}
extension UInt8 {
var c:CGFloat { return CGFloat(self) }
}
extension UInt16 {
var c:CGFloat { return CGFloat(self) }
}
extension UInt32 {
var c:CGFloat { return CGFloat(self) }
}
extension UInt64 {
var c:CGFloat { return CGFloat(self) }
}
extension Int8 {
var c:CGFloat { return CGFloat(self) }
}
extension Int16 {
var c:CGFloat { return CGFloat(self) }
}
extension Int32 {
var c:CGFloat { return CGFloat(self) }
}
extension Int64 {
var c:CGFloat { return CGFloat(self) }
}
extension UInt64 {
var c:CGFloat { return CGFloat(self) }
}
extension MyNumberType {
var c:CGFloat { return CGFloat(self) }
}
extension MyNumberTypeB {
var c:CGFloat { return CGFloat(self) }
}
:
…
…
•
• …
• 

Swift
OK
let a: Float = 190.0
let b: Int = 3
let value = CGFloat(a) + CGFloat(b)
CGFloat
public struct CGFloat {
public init()
public init(_ value: Float)
public init(_ value: Double)
public init(_ value: Float80)
public init(_ value: CGFloat)
public init(_ value: UInt8)
public init(_ value: Int8)
:
• CGFloat
• Int
…
Protocol
Protocol =
• API
•
• Java/C# Interface Ruby mix-in C++
• ( ) protocol
• extension
• /
protocol
extension Int: MyCustomProtocol {}
Swift protocol
Swift protocol
• init
•
protocol CGFConvertible {
init (_ value: Int)
init (_ value: Float)
init (_ value: Double)
init (_ value: CGFloat)
}
//
extension Int: CGFConvertible {}
extension Float: CGFConvertible {}
extension Double: CGFConvertible {}
extension CGFloat: CGFConvertible {}
Generic
•
CGFConvertible 

T
•
•
… Swift 

extension CGFConvertible {
fileprivate func convert
<T: CGFConvertible>() -> T {
return T(self)
}
}
func checkType<T>(_ x: T) {
switch x {
case _ as CGFloat: print("(x) is a CGFloat")
case _ as Float: print("(x) is a Float")
case _ as Int: print("(x) is a Int")
case _ as Double: print("(x) is a Double")
default: print("(x) is unknown..")
}
}
Swift Workaround
RTTI
extension CGFConvertible {
fileprivate func convert<T: CGFConvertible>() -> T {
switch self {
case let x as CGFloat: return T(x)
case let x as Float: return T(x)
case let x as Int: return T(x)
case let x as Double: return T(x)
default:
fatalError("Unsupported format")
}
}
public var c: CGFloat { return convert() }
}
K
…
•
• CGFloat
• Int,Float,Double
let value: Double = Double(CGFloat(3) + 5.cgf)
• / …
let a = CGFloat(10)
let b = 30
let value = a + b // ERROR!
let value = a + 3.14 // ERROR!
CGFConvertible
CGFConvertible
Double
…
…
let a = 3
let x: CGFloat = a + CGFloat(4.2) // OK
let y: CGFloat = a * 4.2 // OK, yay!
extension CGFConvertible {
private typealias CombineType = (Double,Double) -> Double
fileprivate func operate<T:CGFConvertible, V:CGFConvertible>
(b:T, combine: CombineType) -> V {
let x:Double = self.convert()
let y:Double = b.convert()
return combine(x,y).convert()
}
}
func + <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible>
(lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: + )
}
func - <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible>
(lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: - )
}
a.
protocol CGFConvertible {
init (_ value: Int)
init (_ value: Float)
init (_ value: Double)
init (_ value: CGFloat)
}
extension Int: CGFConvertible {}
extension Float: CGFConvertible {}
extension Double: CGFConvertible {}
extension CGFloat: CGFConvertible {}
extension CGFConvertible {
fileprivate func convert<T: CGFConvertible>() -> T
{ return T(x) }
}
•
b.
extension CGFConvertible {
private typealias CombineType = (Double,Double) -> Double
fileprivate func operate<T:CGFConvertible, V:CGFConvertible>
(b:T, combine: CombineType) -> V {
let x:Double = self.convert()
let y:Double = b.convert()
return combine(x,y).convert()
}
}
func + <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible>
(lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: + )
}
func - <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible>
(lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: - )
}
func * <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible>
(lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: * )
}
•
let a = 3
let x: CGFloat = a + CGFloat(4.2) // OK
let y: CGFloat = a * 4.2 // OK, yay!
CGFloat ≠ Float/Double/…
• Objective-C
•
•
•
• /
•
• Swift
• CGFloat
• CGFloat
• Round up a CGFloat in Swift
• Swift
Fighting history of CGFloat in Swift

Contenu connexe

En vedette

English for programmers
English for programmersEnglish for programmers
English for programmersHirohito Kato
 
A4でまとめるClean architecture概要
A4でまとめるClean architecture概要A4でまとめるClean architecture概要
A4でまとめるClean architecture概要Hirohito Kato
 
プログラミングで言いたい聞きたいこと集
プログラミングで言いたい聞きたいこと集プログラミングで言いたい聞きたいこと集
プログラミングで言いたい聞きたいこと集tecopark
 
知らないと損するアプリ開発におけるStateMachineの活用法(full版)
知らないと損するアプリ開発におけるStateMachineの活用法(full版)知らないと損するアプリ開発におけるStateMachineの活用法(full版)
知らないと損するアプリ開発におけるStateMachineの活用法(full版)Ken Morishita
 
Visual studioとそのライバル
Visual studioとそのライバルVisual studioとそのライバル
Visual studioとそのライバルTadahiro Ishisaka
 
Digitization-software is eating the world
Digitization-software is eating the worldDigitization-software is eating the world
Digitization-software is eating the worldKenji Hiranabe
 
160625 cloud samurai_adds_migration_160625
160625 cloud samurai_adds_migration_160625160625 cloud samurai_adds_migration_160625
160625 cloud samurai_adds_migration_160625wintechq
 
デザイン・制作をはじめる前に
取り組む事
デザイン・制作をはじめる前に
取り組む事デザイン・制作をはじめる前に
取り組む事
デザイン・制作をはじめる前に
取り組む事kenji goto
 
メガネ型デバイスの未来について考える
メガネ型デバイスの未来について考えるメガネ型デバイスの未来について考える
メガネ型デバイスの未来について考えるSho Okada
 
HTML5 Conference 2013 HybridCast
HTML5 Conference 2013 HybridCastHTML5 Conference 2013 HybridCast
HTML5 Conference 2013 HybridCastSatoshi Shoda
 
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>Satoru Itabashi
 
Jenkins実践入門 第二版 What's New
Jenkins実践入門 第二版 What's NewJenkins実践入門 第二版 What's New
Jenkins実践入門 第二版 What's NewMasanori Satoh
 
開発者の方向けの Sql server(db) t sql 振り返り
開発者の方向けの Sql server(db) t sql 振り返り開発者の方向けの Sql server(db) t sql 振り返り
開発者の方向けの Sql server(db) t sql 振り返りOda Shinsuke
 
KPTAふりかえり体験研修のご紹介
KPTAふりかえり体験研修のご紹介KPTAふりかえり体験研修のご紹介
KPTAふりかえり体験研修のご紹介ESM SEC
 
Rdra4越境アジャイル
Rdra4越境アジャイルRdra4越境アジャイル
Rdra4越境アジャイルZenji Kanzaki
 
ピクト図解(R)表記ルールver1.0
ピクト図解(R)表記ルールver1.0ピクト図解(R)表記ルールver1.0
ピクト図解(R)表記ルールver1.0PICTO ZUKAI
 
Fitnesse を用いたテストの効率化について
Fitnesse を用いたテストの効率化についてFitnesse を用いたテストの効率化について
Fitnesse を用いたテストの効率化についてtecopark
 
AD設計の基礎から読み解くIaaS On AD
AD設計の基礎から読み解くIaaS On ADAD設計の基礎から読み解くIaaS On AD
AD設計の基礎から読み解くIaaS On ADNaoki Abe
 

En vedette (20)

English for programmers
English for programmersEnglish for programmers
English for programmers
 
A4でまとめるClean architecture概要
A4でまとめるClean architecture概要A4でまとめるClean architecture概要
A4でまとめるClean architecture概要
 
プログラミングで言いたい聞きたいこと集
プログラミングで言いたい聞きたいこと集プログラミングで言いたい聞きたいこと集
プログラミングで言いたい聞きたいこと集
 
知らないと損するアプリ開発におけるStateMachineの活用法(full版)
知らないと損するアプリ開発におけるStateMachineの活用法(full版)知らないと損するアプリ開発におけるStateMachineの活用法(full版)
知らないと損するアプリ開発におけるStateMachineの活用法(full版)
 
Visual studioとそのライバル
Visual studioとそのライバルVisual studioとそのライバル
Visual studioとそのライバル
 
Digitization-software is eating the world
Digitization-software is eating the worldDigitization-software is eating the world
Digitization-software is eating the world
 
160625 cloud samurai_adds_migration_160625
160625 cloud samurai_adds_migration_160625160625 cloud samurai_adds_migration_160625
160625 cloud samurai_adds_migration_160625
 
Rdra in 東京
Rdra in 東京Rdra in 東京
Rdra in 東京
 
デザイン・制作をはじめる前に
取り組む事
デザイン・制作をはじめる前に
取り組む事デザイン・制作をはじめる前に
取り組む事
デザイン・制作をはじめる前に
取り組む事
 
メガネ型デバイスの未来について考える
メガネ型デバイスの未来について考えるメガネ型デバイスの未来について考える
メガネ型デバイスの未来について考える
 
HTML5 Conference 2013 HybridCast
HTML5 Conference 2013 HybridCastHTML5 Conference 2013 HybridCast
HTML5 Conference 2013 HybridCast
 
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>
新規ビジネスデザイン研修 DYA2  テキスト<サンプル版>
 
Jenkins実践入門 第二版 What's New
Jenkins実践入門 第二版 What's NewJenkins実践入門 第二版 What's New
Jenkins実践入門 第二版 What's New
 
開発者の方向けの Sql server(db) t sql 振り返り
開発者の方向けの Sql server(db) t sql 振り返り開発者の方向けの Sql server(db) t sql 振り返り
開発者の方向けの Sql server(db) t sql 振り返り
 
KPTAふりかえり体験研修のご紹介
KPTAふりかえり体験研修のご紹介KPTAふりかえり体験研修のご紹介
KPTAふりかえり体験研修のご紹介
 
Rdra4越境アジャイル
Rdra4越境アジャイルRdra4越境アジャイル
Rdra4越境アジャイル
 
ピクト図解(R)表記ルールver1.0
ピクト図解(R)表記ルールver1.0ピクト図解(R)表記ルールver1.0
ピクト図解(R)表記ルールver1.0
 
Fitnesse を用いたテストの効率化について
Fitnesse を用いたテストの効率化についてFitnesse を用いたテストの効率化について
Fitnesse を用いたテストの効率化について
 
Ad設計
Ad設計Ad設計
Ad設計
 
AD設計の基礎から読み解くIaaS On AD
AD設計の基礎から読み解くIaaS On ADAD設計の基礎から読み解くIaaS On AD
AD設計の基礎から読み解くIaaS On AD
 

Similaire à Fighting history of CGFloat in Swift

Functional Systems @ Twitter
Functional Systems @ TwitterFunctional Systems @ Twitter
Functional Systems @ TwitterC4Media
 
The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189Mahmoud Samir Fayed
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210Mahmoud Samir Fayed
 
Billing in a supermarket c++
Billing in a supermarket c++Billing in a supermarket c++
Billing in a supermarket c++varun arora
 
The Ring programming language version 1.3 book - Part 63 of 88
The Ring programming language version 1.3 book - Part 63 of 88The Ring programming language version 1.3 book - Part 63 of 88
The Ring programming language version 1.3 book - Part 63 of 88Mahmoud Samir Fayed
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
 
Deepak Soni ,BCA Third Year
Deepak Soni ,BCA Third YearDeepak Soni ,BCA Third Year
Deepak Soni ,BCA Third YearDezyneecole
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray EnginePVS-Studio
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019corehard_by
 
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018Masashi Shibata
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-Gota Kakehi
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationKevin Keraudren
 
CocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads France
 

Similaire à Fighting history of CGFloat in Swift (20)

Functional Systems @ Twitter
Functional Systems @ TwitterFunctional Systems @ Twitter
Functional Systems @ Twitter
 
The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202The Ring programming language version 1.8 book - Part 12 of 202
The Ring programming language version 1.8 book - Part 12 of 202
 
The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210The Ring programming language version 1.9 book - Part 14 of 210
The Ring programming language version 1.9 book - Part 14 of 210
 
Billing in a supermarket c++
Billing in a supermarket c++Billing in a supermarket c++
Billing in a supermarket c++
 
Vcs15
Vcs15Vcs15
Vcs15
 
The Ring programming language version 1.3 book - Part 63 of 88
The Ring programming language version 1.3 book - Part 63 of 88The Ring programming language version 1.3 book - Part 63 of 88
The Ring programming language version 1.3 book - Part 63 of 88
 
Scala.io
Scala.ioScala.io
Scala.io
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer Graphics
 
Deepak Soni ,BCA Third Year
Deepak Soni ,BCA Third YearDeepak Soni ,BCA Third Year
Deepak Soni ,BCA Third Year
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray Engine
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-
Kinect勉強会 Vol.3 -ぼくのかんがえた最強のNUI-
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
 
CocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIView
 

Plus de Hirohito Kato

functional programming & c++
functional programming & c++functional programming & c++
functional programming & c++Hirohito Kato
 
Linux device driver for dummies
Linux device driver for dummiesLinux device driver for dummies
Linux device driver for dummiesHirohito Kato
 
subversion hacks (create a commit template)
subversion hacks (create a commit template)subversion hacks (create a commit template)
subversion hacks (create a commit template)Hirohito Kato
 
Git flowの活用事例
Git flowの活用事例Git flowの活用事例
Git flowの活用事例Hirohito Kato
 
yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料Hirohito Kato
 

Plus de Hirohito Kato (6)

functional programming & c++
functional programming & c++functional programming & c++
functional programming & c++
 
Linux device driver for dummies
Linux device driver for dummiesLinux device driver for dummies
Linux device driver for dummies
 
subversion hacks (create a commit template)
subversion hacks (create a commit template)subversion hacks (create a commit template)
subversion hacks (create a commit template)
 
Git flowの活用事例
Git flowの活用事例Git flowの活用事例
Git flowの活用事例
 
yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料
 
Mosquito Attack
Mosquito AttackMosquito Attack
Mosquito Attack
 

Dernier

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Dernier (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Fighting history of CGFloat in Swift

  • 2. • try! Swift 2016 
 Swift (@RGfox)
 • ( ) 

  • 4.
  • 5.
  • 6. CGFloat • Core Graphics • • SpriteKit/SceneKit UIKit •
  • 7. CGFloat • double / float typedef • CPU • double
  • 8. • CGFloat • NSNumber CGFloat • double • iOS iPhone5 or iPhone5S 

  • 10.
  • 13.
  • 17.
  • 18.
  • 19. let value1: CGFloat = 240 // OK
  • 20. let value1: CGFloat = 240 // OK let value2: CGFloat = 80.0 // OK
  • 21.
  • 22. let a = CGFloat(10)
  • 23. let a = CGFloat(10) let b = 30
  • 24. let a = CGFloat(10) let b = 30 let value = a + b // ERROR!
  • 25. let a = CGFloat(10) let b = 30 let value = a + b // ERROR! let value = a + CGFloat(b) // OK
  • 26.
  • 27. let pos = CGPoint(x: 160, y: 80.0)
  • 28. let pos = CGPoint(x: 160, y: 80.0) // OK
  • 29. let pos = CGPoint(x: 160, y: 80.0) // OK let a = 160
  • 30. let pos = CGPoint(x: 160, y: 80.0) // OK let a = 160 let pos = CGPoint(x: a, y: 80.0)
  • 31. let pos = CGPoint(x: 160, y: 80.0) // OK let a = 160 let pos = CGPoint(x: a, y: 80.0) // ERROR!
  • 32. let pos = CGPoint(x: 160, y: 80.0) // OK let a = 160 let pos = CGPoint(x: a, y: 80.0) // ERROR!
  • 33.
  • 34. let x = 32
  • 35. let x = 32 let y = 120.0
  • 36. let x = 32 let y = 120.0 let w = Float(44.0)
  • 37. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24)
  • 38. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x,
  • 39. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x, y: y,
  • 40. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x, y: y, width: w,
  • 41. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x, y: y, width: w, height: h)
  • 42. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x, y: y, width: w, height: h) // ERROR!
  • 43. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: x, y: y, width: w, height: h) // ERROR!
  • 44.
  • 45. let x = 32
  • 46. let x = 32 let y = 120.0
  • 47. let x = 32 let y = 120.0 let w = Float(44.0)
  • 48. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24)
  • 49. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x),
  • 50. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x), y: CGFloat(y),
  • 51. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(w),
  • 52. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(w), height: h)
  • 53. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(w), height: h) // OK
  • 54. let x = 32 let y = 120.0 let w = Float(44.0) let h = CGFloat(24) view.rect = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(w), height: h) // OK
  • 55.
  • 56.
  • 59.
  • 61.
  • 62.
  • 63. extension Double { var cgf:CGFloat { return CGFloat(self) } } let y = 1 + 10.0.cgf // OK, yay!
  • 64. extension Double { var cgf:CGFloat { return CGFloat(self) } } extension Int { var cgf:CGFloat { return CGFloat(self) } } extension Float { var cgf:CGFloat { return CGFloat(self) } }
  • 65.
  • 66. extension Double { var c:CGFloat { return CGFloat(self) } } extension Int { var c:CGFloat { return CGFloat(self) } } extension Float { var c:CGFloat { return CGFloat(self) } } extension Float80 { var c:CGFloat { return CGFloat(self) } } extension UInt { var c:CGFloat { return CGFloat(self) } } extension UInt8 { var c:CGFloat { return CGFloat(self) } } extension UInt16 { var c:CGFloat { return CGFloat(self) } } extension UInt32 { var c:CGFloat { return CGFloat(self) } } extension UInt64 { var c:CGFloat { return CGFloat(self) } } extension Int8 { var c:CGFloat { return CGFloat(self) } } extension Int16 { var c:CGFloat { return CGFloat(self) } } extension Int32 { var c:CGFloat { return CGFloat(self) } } extension Int64 { var c:CGFloat { return CGFloat(self) } } extension UInt64 { var c:CGFloat { return CGFloat(self) } } extension MyNumberType { var c:CGFloat { return CGFloat(self) } } extension MyNumberTypeB { var c:CGFloat { return CGFloat(self) } } : …
  • 68.
  • 69. Swift
  • 70.
  • 71. OK let a: Float = 190.0 let b: Int = 3 let value = CGFloat(a) + CGFloat(b)
  • 72. CGFloat public struct CGFloat { public init() public init(_ value: Float) public init(_ value: Double) public init(_ value: Float80) public init(_ value: CGFloat) public init(_ value: UInt8) public init(_ value: Int8) :
  • 75. Protocol = • API • • Java/C# Interface Ruby mix-in C++
  • 76. • ( ) protocol • extension • / protocol extension Int: MyCustomProtocol {} Swift protocol
  • 77. Swift protocol • init • protocol CGFConvertible { init (_ value: Int) init (_ value: Float) init (_ value: Double) init (_ value: CGFloat) } // extension Int: CGFConvertible {} extension Float: CGFConvertible {} extension Double: CGFConvertible {} extension CGFloat: CGFConvertible {}
  • 80. • … Swift 
 extension CGFConvertible { fileprivate func convert <T: CGFConvertible>() -> T { return T(self) } }
  • 81. func checkType<T>(_ x: T) { switch x { case _ as CGFloat: print("(x) is a CGFloat") case _ as Float: print("(x) is a Float") case _ as Int: print("(x) is a Int") case _ as Double: print("(x) is a Double") default: print("(x) is unknown..") } } Swift Workaround RTTI
  • 82. extension CGFConvertible { fileprivate func convert<T: CGFConvertible>() -> T { switch self { case let x as CGFloat: return T(x) case let x as Float: return T(x) case let x as Int: return T(x) case let x as Double: return T(x) default: fatalError("Unsupported format") } } public var c: CGFloat { return convert() } } K
  • 83. … • • CGFloat • Int,Float,Double let value: Double = Double(CGFloat(3) + 5.cgf)
  • 84.
  • 85. • / … let a = CGFloat(10) let b = 30 let value = a + b // ERROR! let value = a + 3.14 // ERROR!
  • 89.
  • 90. let a = 3 let x: CGFloat = a + CGFloat(4.2) // OK let y: CGFloat = a * 4.2 // OK, yay!
  • 91. extension CGFConvertible { private typealias CombineType = (Double,Double) -> Double fileprivate func operate<T:CGFConvertible, V:CGFConvertible> (b:T, combine: CombineType) -> V { let x:Double = self.convert() let y:Double = b.convert() return combine(x,y).convert() } } func + <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible> (lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: + ) } func - <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible> (lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: - ) }
  • 92.
  • 93. a. protocol CGFConvertible { init (_ value: Int) init (_ value: Float) init (_ value: Double) init (_ value: CGFloat) } extension Int: CGFConvertible {} extension Float: CGFConvertible {} extension Double: CGFConvertible {} extension CGFloat: CGFConvertible {} extension CGFConvertible { fileprivate func convert<T: CGFConvertible>() -> T { return T(x) } } •
  • 94. b. extension CGFConvertible { private typealias CombineType = (Double,Double) -> Double fileprivate func operate<T:CGFConvertible, V:CGFConvertible> (b:T, combine: CombineType) -> V { let x:Double = self.convert() let y:Double = b.convert() return combine(x,y).convert() } } func + <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible> (lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: + ) } func - <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible> (lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: - ) } func * <T:CGFConvertible, U:CGFConvertible,V:CGFConvertible> (lhs: T, rhs: U) -> V { return lhs.operate(b: rhs, combine: * ) } •
  • 95. let a = 3 let x: CGFloat = a + CGFloat(4.2) // OK let y: CGFloat = a * 4.2 // OK, yay!
  • 96.
  • 97.
  • 98. CGFloat ≠ Float/Double/… • Objective-C • • • • / • • Swift
  • 99. • CGFloat • CGFloat • Round up a CGFloat in Swift • Swift