Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
180
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
360
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
820
Mobile Programming Protocol Extension
yuichirokato
0
84
Mobile Programming Protocol
yuichirokato
0
90
Mobile Programming enum
yuichirokato
0
170
Mobile Programming Optional
yuichirokato
0
140
Mobile Programming Struct
yuichirokato
0
130
Mobile Programming Initializer Beta
yuichirokato
0
130
Mobile Programming Inheritance
yuichirokato
0
160
Other Decks in Technology
See All in Technology
ハッカソンから社内プロダクトへ AIエージェント「ko☆shi」開発で学んだ4つの重要要素
sonoda_mj
6
1.7k
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
1
410
Connection-based OAuthから学ぶOAuth for AI Agents
flatt_security
0
370
普段使ってるClaude Skillsの紹介(by Notebooklm)
zerebom
8
2.2k
Strands Agents × インタリーブ思考 で変わるAIエージェント設計 / Strands Agents x Interleaved Thinking AI Agents
takanorig
5
2.1k
Strands AgentsとNova 2 SonicでS2Sを実践してみた
yama3133
1
1.9k
Microsoft Agent Frameworkの可観測性
tomokusaba
1
110
Lookerで実現するセキュアな外部データ提供
zozotech
PRO
0
200
アラフォーおじさん、はじめてre:Inventに行く / A 40-Something Guy’s First re:Invent Adventure
kaminashi
0
160
AI との良い付き合い方を僕らは誰も知らない
asei
0
270
たまに起きる外部サービスの障害に備えたり備えなかったりする話
egmc
0
410
AWSに革命を起こすかもしれない新サービス・アップデートについてのお話
yama3133
0
510
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
49
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
69
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
29
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
91
Agile that works and the tools we love
rasmusluckow
331
21k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.4k
The SEO identity crisis: Don't let AI make you average
varn
0
39
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
190
Building a Scalable Design System with Sketch
lauravandoore
463
34k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
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 ѻ͍ʹͳΔ