Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Essentials in SwiftUI

Data Essentials in SwiftUI

集まれSwift好き!Swift愛好会スピンオフ WWDC20セッション要約会 @オンライン

ry-itto

July 09, 2020
Tweet

More Decks by ry-itto

Other Decks in Programming

Transcript

  1. 4XJGU6*Ͱͷσʔλϑϩʔ ϏϡʔΛ࡞Δ࣌ʹߟ͍͑ͨ̏ͭͷ࣭໰ w ࡞੒͢ΔϏϡʔͰඞཁͳσʔλ͸Կ͔ʁ CPPLͱ͍͏#PPLܕͷ஋ QSPHSFTTͱ͍͏%PVCMFܕͷ஋ ͦΕͧΕ͕͋Ε͹ϏϡʔΛදࣔͰ͖ͦ͏ɻ w ࡞੒͢ΔϏϡʔͰ͸σʔλΛͲͷΑ͏ʹૢ࡞͢Δ ͔ʁ

    ಛʹͳͦ͞͏ w σʔλ͸Ͳ͔͜ΒདྷΔʢ౉͞ΕΔʣͷ͔ʁ ͜ͷϏϡʔΛ࢖͏ϏϡʔͰ౉͞ΕΔ͜ͱʹͳΓͦ͏ɻ struct BookCard : View { let book: Book let progress: Double var body: some View { HStack { Cover(book.coverName) VStack(alignment: .leading) { TitleText(book.title) AuthorText(book.author) } Spacer() RingProgressView(value: progress) } } }
  2. 4XJGU6*Ͱͷσʔλϑϩʔ ϏϡʔΛ࡞Δ࣌ʹߟ͍͑ͨ̏ͭͷ࣭໰ w ࡞੒͢ΔϏϡʔͰඞཁͳσʔλ͸Կ͔ʁ CPPLͱ͍͏#PPLܕͷ஋ QSPHSFTTͱ͍͏%PVCMFܕͷ஋ ͦΕͧΕ͕͋Ε͹ϏϡʔΛදࣔͰ͖ͦ͏ɻ w ࡞੒͢ΔϏϡʔͰ͸σʔλΛͲͷΑ͏ʹૢ࡞͢ Δ͔ʁ

    ಛʹͳͦ͞͏ w σʔλ͸Ͳ͔͜ΒདྷΔʢ౉͞ΕΔʣͷ͔ʁ ͜ͷϏϡʔΛ࢖͏ϏϡʔͰ౉͞ΕΔ͜ͱʹͳΓͦ͏ɻ struct BookCard : View { let book: Book let progress: Double var body: some View { HStack { Cover(book.coverName) VStack(alignment: .leading) { TitleText(book.title) AuthorText(book.author) } Spacer() RingProgressView(value: progress) } } } l4PVSDFPG5SVUIzͱ͍͏ݴ༿Ͱηογϣϯ಺Ͱ͸ѻΘΕΔ
  3. ΞϓϦͷσʔλϞσϧઃܭ σʔλϞσϧఆٛ w 0CTFSWBCMF0CKFDUΛ࢖͏ w !1VCMJTIFEΛ࢖͏ w ̎ͭ໨ͷ࣭໰ ࡞੒͢ΔϏϡʔͰ͸σʔλΛͲͷΑ͏ʹૢ࡞͢ Δ͔ʁ

     ʹ౴͑Δͷ͸༰қ class CurrentlyReading: ObservableObject { let book: Book @Published var progress = ReadingProgress() @Published var isFinished = false var currentProgress: Double { isFinished ? 1.0 : progress.progress } }
  4. ࣮ࡍʹΞϓϦʹऔΓೖΕΔࡍͷςΫχοΫ ໰୊ w ࢠͷϏϡʔͰϞσϧΛϓϩύςΟͰ ͍࣋ͬͯͯɺͦ͜ͰॳظԽ͍ͯ͠Δ ৔߹ w 3FBEJOH-JTU7JFXFS͕ࡍϨϯμϦϯά͞ ΕΔͨͼʹϞσϧͷΠϯελϯε͕ੜ੒ ͞Εͯ͠·͏

    struct ReadingListViewer: View { var body: some View { NavigationView { ReadingList() Placeholder() } } } struct ReadingList: View { @ObservedObject var store = ReadingListStore() var body: some View { // ... } }
  5. ࣮ࡍʹΞϓϦʹऔΓೖΕΔࡍͷςΫχοΫ ղܾࡦ w !4UBUF0CKFDUΛ୅ΘΓʹ࢖͏͜ͱ Ͱղܾ͕Ͱ͖ΔʢΒ͍͠ʣ w !4UBUF0CKFDUΛ࢖༻͢Δͱ4XJGU6*͕ ద੾ͳλΠϛϯάͰΠϯελϯεԽΛ͠ ͯ͘ΕΔͱͷ͜ͱ struct

    ReadingListViewer: View { var body: some View { NavigationView { ReadingList() Placeholder() } } } struct ReadingList: View { @StateObject var store = ReadingListStore() var body: some View { // ... } }