Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
210
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
140
CustomCopを使ってMongoidのコーディングルールを整えてみた
jinoketani
0
220
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.1k
UI State設計とテスト方針
rmakiyama
2
260
Password-less Journey - パスキーへの移行を見据えたユーザーの準備 @ AXIES 2024
ritou
3
1.4k
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
1
110
MLOps の現場から
asei
6
630
Featured
See All Featured
Done Done
chrislema
181
16k
Producing Creativity
orderedlist
PRO
341
39k
Rails Girls Zürich Keynote
gr2m
94
13k
A Philosophy of Restraint
colly
203
16k
Code Review Best Practice
trishagee
65
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building Applications with DynamoDB
mza
91
6.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 ѻ͍ʹͳΔ