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
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mobile Programing Property & Method
Mobile Programming の授業で使うスライドです
yuichiro_takahashi
November 12, 2018
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
610
App Clip - in a nutshell
yuichirokato
0
390
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
850
Mobile Programming Protocol Extension
yuichirokato
0
96
Mobile Programming Protocol
yuichirokato
0
100
Mobile Programming enum
yuichirokato
0
190
Mobile Programming Optional
yuichirokato
0
150
Mobile Programming Struct
yuichirokato
0
140
Mobile Programming Initializer Beta
yuichirokato
0
150
Other Decks in Technology
See All in Technology
AI Coding Agent時代のcdk-nagガードレール 〜組織ルールを強制CIで守り抜く設計の挑戦〜
mhrtech
3
390
AIと共生する開発者プラットフォーム:バクラクのモノレポ×マイクロサービス基盤
sakajunquality
2
3.7k
【Claude Code】鹿野さんに聞く 私の推しの並行開発環境 大公開 / claude-code-parallel-2026-07-15
tonkotsuboy_com
12
8.6k
ファミコンでPHPを動かす / PHP on the Famicom
tomzoh
2
350
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.5k
公式ドキュメントの歩き方etc
coco_se
1
120
しくみを学んで使いこなそう GitHub Copilot app
torumakabe
2
290
生成AI×AWS CDK×AWS FISで"振り返れる"ミニGameDayをつくろう
yoshimi0227
1
370
AICoEでAIネイティブ組織への進化
yukiogawa
0
190
LLMやAIエージェントをソフトウェアに組み込むプラクティス
shibuiwilliam
2
420
脱金融のフューチャー・デザイン / Future Design Beyond Finance
ks91
PRO
0
160
見守りエージェントを作ってみた(ローカルLLM + Hermes Agent)
happysamurai294
0
110
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Mobile First: as difficult as doing things right
swwweet
225
10k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
WENDY [Excerpt]
tessaabrams
11
38k
Paper Plane (Part 1)
katiecoart
PRO
1
9.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Site-Speed That Sticks
csswizardry
13
1.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
Marketing to machines
jonoalderson
1
5.6k
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 ѻ͍ʹͳΔ