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
150
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
280
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
750
Mobile Programming Protocol Extension
yuichirokato
0
74
Mobile Programming Protocol
yuichirokato
0
79
Mobile Programming enum
yuichirokato
0
150
Mobile Programming Optional
yuichirokato
0
130
Mobile Programming Struct
yuichirokato
0
120
Mobile Programming Initializer Beta
yuichirokato
0
110
Mobile Programming Inheritance
yuichirokato
0
140
Other Decks in Technology
See All in Technology
楽しくGoを学び合う、LayerXの勉強会文化 / LayerX's study culture of having fun and learning Go together
ar_tama
2
350
「単なる OAuth 2.0 を認証に使うと、車が通れるほどのどでかいセキュリティー・ホールができる」のか検証してみた
terara
0
380
目標設定は好きですか? アジャイルとともに目標と向き合い続ける方法 / Do you like target Management?
kakehashi
10
3k
エンジニアリングマネージャーはどう学んでいくのか #devsumi / How Do Engineering Managers Continue to Learn and Grow?
expajp
4
1.3k
Scaling Technical Excellence at 104: Evolution in AWS and Developer Empowerment
scotthsieh825
1
160
技術負債による事業の失敗はなぜ起こるのか / Why do business failures due to technical debt occur?
i35_267
0
190
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
0
480
ペパボのオブザーバビリティ研修2024 説明資料
kesompochy
0
1.1k
Android研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
100
AutomatedLabを使って内部ペンテストを勉強しよう! -やられ社内ネットワークの自動構築-
n_etupirka
1
610
AWSで”最小権限の原則”を実現するための考え方 /20240722-ssmjp-aws-least-privilege
opelab
10
4.4k
Matterport を使ってクラスメソッド各拠点のバーチャルオフィスツアーを作成してみた
wakatsuki
0
160
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
325
20k
Building Effective Engineering Teams - LeadDev
addyosmani
47
2.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
15
4.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.8k
In The Pink: A Labor of Love
frogandcode
139
22k
Web Components: a chance to create the future
zenorocha
307
41k
How STYLIGHT went responsive
nonsquared
93
5k
Testing 201, or: Great Expectations
jmmastey
33
6.9k
Web development in the modern age
philhawksworth
203
10k
Scaling GitHub
holman
458
140k
Infographics Made Easy
chrislema
238
18k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
24
1.8k
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 ѻ͍ʹͳΔ