Data Flow Through SwiftUI

Woozoo·2023년 3월 31일
0

[Whatis]

목록 보기
3/8

https://developer.apple.com/videos/play/wwdc2019/226/

프레젠테이션 슬라이드

Principles of Data Flow

[PlayerView] ---- [true]

Source of Truth

  • Property Wrapper
    Wraps property Access with additional Behavior

  • @Binding Property Wrapper
    Read and write without ownership
    Derivable from @State

Anatomy of an Update

class PodcastPlayserStore: BindableObject {
	var didChange = PassthroughSubject<Void, Never>()
    //...
    func advance() {
    	currentEpisode = nextEpisode
        currentTime = 0.0
        // Notofy subscribers that the palyer changed
        didChange.send()
    }
}

BindableObject?

struct MyView: View {
	@ObjectBinding var model: MyModelObject
    ...
}

MyView(model: modelInstance)

Environment

Data applicable to an entire hierarchy
Convenience for indirection
Accent color, right-to-left, and more

Understanding Your Data


  • @State
    View - local
    Value
    Framework Managed

  • Bindable Object
    External
    Reference
    Developer Managed

  • @Binding
    First class reference to data
    Great for reusability
    Use $ to derive from source


Using State Effectively

Limit use if possible
Use derived Binding or value
Prefer Bindable Object for persistence
Example: Button highlighting

profile
우주형

0개의 댓글

관련 채용 정보