$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mobile Programing Property & Method
Search
yuichiro_takahashi
November 12, 2018
Technology
0
160
Mobile Programing Property & Method
Mobile Programming の授業で使うスライドです
yuichiro_takahashi
November 12, 2018
Tweet
Share
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
App Clip - in a nutshell
yuichirokato
0
310
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
770
Mobile Programming Protocol Extension
yuichirokato
0
77
Mobile Programming Protocol
yuichirokato
0
79
Mobile Programming enum
yuichirokato
0
160
Mobile Programming Optional
yuichirokato
0
130
Mobile Programming Struct
yuichirokato
0
120
Mobile Programming Initializer Beta
yuichirokato
0
120
Mobile Programming Inheritance
yuichirokato
0
140
Other Decks in Technology
See All in Technology
農業用ダム監視を目的とした衛星SAR 干渉解析の適用性について
osgeojp
0
140
.NET のUnified AI Building Blocks 入門...!
okazuki
0
170
Nihonbashi Test Talk #3_WebDriver BiDiと最新の実装状況 / WebDriver BiDi latest status
takeyaqa
1
130
LangChainとSupabaseを活用して、RAGを実装してみた
atsushii
0
130
スパイクアクセス対策としての pitchfork 導入
riseshia
0
110
実践/先取り「入門 Kubernetes Validating/Mutating Admission Policy」 / CloudNative Days Winter 2024
pfn
PRO
1
150
GeminiとUnityで実現するインタラクティブアート
hokkey621
0
530
アジャイルテストの4象限で考える プロダクト開発の品質への向き合い方
nagano
1
230
MediaPipe と ML Kit ってどう ちがうの? / What is the difference between MediaPipe and ML Kit?
yanzm
0
420
40歲的我會給20歲的自己,關於軟體開發的7個建議
line_developers_tw
PRO
0
120
A/Aテストにおけるサンプルサイズ/japanr2024
nikkei_engineer_recruiting
1
310
Atelier BlueHats : Migration de l’application COBOL MedocDB de GCOS à GnuCOBOL sur GNU/Linux
bluehats
0
110
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
280
34k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Cost Of JavaScript in 2023
addyosmani
45
6.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Statistics for Hackers
jakevdp
796
220k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.1k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Transcript
ϓϩύςΟͱϝιου MOBILE PROGRAMMING 11TH NOV
લճ·Ͱͷ͋ Β͢͡
ςΩετ 2. CLASSͷཁૉ ▸ Classͷதʹ༷ʑͳཁૉ͕ଘࡏ͠·͢ class Dog: Animal { let
name: String private let kind: String init(name: String, kind: String) { self.name = name self.kind = kind } func selfIntroduction() { print("My name is \(name)") print("I'm \(kind)") print("nice to meet you sir.") } } ܧঝ Property ΞΫηεम০ࢠ initializer(constructor) Method
ࠓճɾɾɾ
ςΩετ ͜ͷΜͷཁૉʹ͍͓ͭͯ͠͠·͢ ▸ Classͷதʹ༷ʑͳཁૉ͕ଘࡏ͠·͢ class Dog: Animal { let name:
String private let kind: String init(name: String, kind: String) { self.name = name self.kind = kind } func selfIntroduction() { print("My name is \(name)") print("I'm \(kind)") print("nice to meet you sir.") } } Property ΞΫηεम০ࢠ Method
1. PROPERTY
ςΩετ ϓϩύςΟ(PROPERTY)ͱʁ ▸ ؆୯ʹ͍͏ͱΫϥεͷதʹఆٛ͞Ε͍ͯΔมͷ͜ͱ ▸ ͦͷΫϥε͕ͲΜͳσʔλΛ͔࣋ͭΛද͢ ▸ ྫ͑UILabel text
ͱ͍͏໊લͷϓϩύςΟΛ͍࣋ͬͯΔ ▸ Labelʹදࣔ͢ΔจࣈྻͷσʔλͷͨΊͷϓϩύςΟ ▸ Propertyʹ༷ʑͳछྨ͕͋Δ
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] // Initializer(Constructor) init(name: String, type1: String, type2: String?, ability: [String]) { self.name = name self.type1 = type1 self.type2 = type2 self.ability = ability } // Method func doAbility(name: String) { print("\(self.name)\(name)Λͬͨʂ") print("͔͠͠Կى͜Βͳ͍ʂ") } } ͜ͷ෦͕Property
1-1. STORED PROPERTY
ςΩετ STORED PROPERTYͱʁ ▸ ҰൠతͳϓϩύςΟ ▸ ຊޠͰ֨ೲܕϓϩύςΟ ▸ σʔλΛΠχγϟϥΠβΠϯελϯεԽͨ͠ޙʹೖͯ͠ ͏
▸ جຊతͳ͍ํී௨ͷม, ఆͱมΘΒͳ͍ ▸ ఆ initializer ͰͷΈΛଋറՄೳ
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] } let slowpoke = Pokemon(name: "Ϡυϯ", type1: "Έͣ", type2: "Τεύʔ", ability: ["ͶΜΓ͖", "ΈͣͰͬΆ͏", "ͳ·͚Δ", "Ͷͬͱ͏"] ) // var Ͱఆٛ͞Ε͍ͯΔͷͰೖՄೳ slowpoke.ability = ["ͳ·͚Δ", "ྫྷౚϏʔϜ", "ϋΠυϩϙϯϓ", “ͲΕ”] // let Ͱఆٛ͞Ε͍ͯΔͷͰ͜ΕͰ͖ͳ͍ slowpoke.name = “Ϡυϥϯ" ͜Εશ෦ Stored Property
1-2. COMPUTED PROPERTY
ςΩετ COMPUTED PROPERTYͱʁ ▸ ͜ΕগʑಛघͳϓϩύςΟ ▸ ຊޠͰܭࢉܕϓϩύςΟͱݺΕΔ ▸ ඞͣ var
Ͱఆٛ͞ΕΔ ▸ จ๏ var propertyName: Type { return value } ▸ ֨ೲܕͷϓϩύςΟͱҧ͍ϓϩύςΟʹΞΫηε͢Δͨͼʹϒ ϩοΫͷதͷॲཧ͕࣮ߦ͞Ε͕ͯฦ͞ΕΔ ▸ ࣌ؒͷ͔͔ΔॲཧೖΕͪΌμϝ
ͲΜͳ࣌ʹ ͏͔ʁ
ϙέϞϯͷྫ Λߟ͑·͢
ςΩετ ϙέϞϯͷྫ ▸ ϙέϞϯਤؑΛ࡞Δ߹Λߟ͑·͢ ▸ ϠυϯͷΑ͏ʹೋͭͷλΠϓΛ࣋ͭ ϙέϞϯ ▸ λΠϓ1/λΠϓ2ͱ͍͏ܗͰදࣔ͞ Ε·͢
▸ ͜ͷจࣈΛදࣔ͢Δࡍʹߦ͏ॲཧ ࣍ͷΑ͏ʹͳΔͣ
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] } let slowpoke = Pokemon(name: "Ϡυϯ", type1: "Έͣ", type2: "Τεύʔ", ability: ["ͶΜΓ͖", "ΈͣͰͬΆ͏", "ͳ·͚Δ", "Ͷͬͱ͏"] ) let type1 = slowpoke.type1 if let type2 = slowpoke.type2 { print("λΠϓ: \(type1)/\(type2)") } else { print("λΠϓ: \(type1)") } ͜Εશ෦ Stored Property
COMPUTED PROPERTY Λ͏ͱ
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] // Computed Property var typeText: String { if let t2 = type2 { return "λΠϓ: \(type1)/\(t2)" } return "λΠϓ: \(type1)" } } let slowpoke = Pokemon(name: "Ϡυϯ", type1: "Έͣ", type2: "Τεύʔ", ability: ["ͶΜΓ͖", "ΈͣͰͬΆ͏", "ͳ·͚Δ", "Ͷͬͱ͏"] ) print(slowpoke.typeText) ͜Ε͕ Computed Property
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] // Computed Property var typeText: String { if let t2 = type2 { return "λΠϓ: \(type1)/\(t2)" } return "λΠϓ: \(type1)" } } let slowpoke = Pokemon(name: "Ϡυϯ", type1: "Έͣ", type2: "Τεύʔ", ability: ["ͶΜΓ͖", "ΈͣͰͬΆ͏", "ͳ·͚Δ", "Ͷͬͱ͏"] ) print(slowpoke.typeText) ͜Ε͕ Computed Property ΞΫηεͷํ Stored Propertyͱಉ͡
1-3. LAZY PROPERTY
ςΩετ LAZY PROPERTYͱʁ ▸ ͜ΕগʑಛघͳϓϩύςΟ ▸ ຊޠͰԆܕϓϩύςΟͱݺΕΔ ▸ ͪ͜Βඞͣ var
Ͱఆٛ͞ΕΔ ▸ จ๏ lazy var propertyName: Type { return value }() ▸ ѻ͍ํ΄ͱΜͲ stored property ͱಉ͕ͩ͡ ▸ ࠷ॳʹΞΫηε͞ΕΔ·ͰॳظԽ͕͞Εͳ͍ ▸ ͪ͜Βٯʹ࣌ؒͷ͔͔ΔॲཧΛೖΕΔͨΊʹ͏ ▸ ViewControllerͰΑ͍͘·͢
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Property let name: String
let type1: String let type2: String? var ability: [String] lazy var skill: String = { return "͍͔͘" }() } let slowpoke = Pokemon(name: "Ϡυϯ", type1: "Έͣ", type2: "Τεύʔ", ability: ["ͶΜΓ͖", "ΈͣͰͬΆ͏", "ͳ·͚Δ", "Ͷͬͱ͏"] ) print(slowpoke.skill) ͜Ε͕ Lazy Property ΞΫηεͷํ Stored Propertyͱಉ͕ͩ͡ ݺΕΔ·ͰॳظԽ͞Εͳ͍
2 PROPERTY OBSERVING
ςΩετ PROPERTY OBSERVINGͱʁ ▸ ͪ͜ΒϓϩύςΟͷछྨͰͳ͘ϓϩύςΟͷػೳ ▸ Observeࢹͱ͍͏ҙຯ ▸ ϓϩύςΟͷมߋΛݕͯ͠ॲཧΛهड़͢Δ͜ͱ͕Ͱ͖ΔΑ͏ʹͳΔػೳ ▸
ϓϩύςΟͷมߋલʹݺΕΔ willSet { … } ▸ ϓϩύςΟͷมߋޙʹݺΕΔ didSet { … } ▸ ͷ2छྨ ▸ { … } ʹॲཧΛॻ͖ࠐΜͰ͍͘
2. ϝιου
ςΩετ ϝιουʁ ▸ ΫϥεߏମͳͲʹఆٛ͞Ε͍ͯΔؔͷ͜ͱ ▸ ओʹΠϯελϯε͕อ͍࣋ͯ͠ΔσʔλΛՃͨ͠Γมߋ͠ ͨΓ͢Δ ▸ ϝιου͔Βಉ͡Ϋϥεʹఆٛ͞Ε͍ͯΔଞͷϝιου ϓϩύςΟʹΞΫηε͢Δ͜ͱ͕Ͱ͖Δ
▸
ςΩετ ࣮ࡍͷίʔυ class Pokemon { // Stored Property let name:
String // লུɾɾɾ // Initializer(Constructor) init(name: String, type1: String, type2: String?, ability: [String]) { // লུɾɾɾ } // Method func doAbility(name: String) { print("\(self.name)\(name)Λͬͨʂ") print("͔͠͠Կى͜Βͳ͍ʂ") } func getAbility(abilityName: String) { } func forgetAbility(abilityName: String) { } } // ϝιουݺͼग़͠ slowpoke.doAbility(name: “ͳ·͚Δ") ͜Ε͕ϝιουఆٛ ͜Ε͕ϝιουݺͼग़͠
3. ΞΫηεम ০ࢠ
ςΩετ ΞΫηεम০ࢠʁ ▸ ӳޠͰ Access Control ▸ มఆɺΫϥεɺϝιουͳͲʹର͢ΔΞΫηεͷ੍ݶΛཧͰ͖Δػೳ ▸ ͜ΕʹΑΓΫϥεͷ֎͔Β৮ͬͯཉ͘͠ͳ͍ϓϩύςΟϝιουΛӅ͢͜ͱ͕Ͱ͖
ΔΑ͏ʹͳͬͨΓ ▸ ٯʹϞδϡʔϧͷ֎ʹ·Ͱެ։͢Δ͜ͱͰ͖ΔΑ͏ʹͳΔ(ผϓϩδΣΫτ͔Βݟ͑ ΔΑ͏ʹͳΔ) ▸ SwiftͰΏΔ͍ॱʹ open, public, internal, fileprivate, private ͷޒ͕ͭଘࡏ͢Δ ▸ ΫϥεϓϩύςΟɺϝιουͷલʹ͚ͭͯ͏ ▸ σϑΥϧτͰ internal
ςΩετ ҧ͍·ͱΊ ग़య: https://qiita.com/GATA/items/90341f56a56ff584e756
ςΩετ ࣮ࡍͷίʔυ open class Pokemon { // Stored Property let
name: String // লུɾɾɾ // Initializer(Constructor) init(name: String, type1: String, type2: String?, ability: [String]) { // লུɾɾɾ } // Method private func doAbility(name: String) { print("\(self.name)\(name)Λͬͨʂ") print("͔͠͠Կى͜Βͳ͍ʂ") } func getAbility(abilityName: String) { } func forgetAbility(abilityName: String) { } } // Error! slowpoke.doAbility(name: “ͳ·͚Δ") ݺͼग़ͤͳ͘ͳΔ ͜ͷϝιουΛϓϥΠϕʔτʹ ΫϥεΦʔϓϯʹ(ผϓϩδΣΫτ͔Βݟ͑Δ) Կఆٛ͠ͳ͍߹ internal ѻ͍ʹͳΔ