Try   HackMD

cs193p

Lecture 13: Publisher More Persistence

  • publishers
  • more persistence
    • cloudKit
    • coredata

0:39 Publisher

  • what is publisher?
  • what can we do with a Publisher?
  • listening (subscribing) to a Publisher
    • .sink
    • .onReceive
  • where do Publisher come from?
    • URLSession
    • Timer
    • NotificationCenter

11:54 Code

class Document: ObserableObject { @Published var backgroundImage: UIImage? } var document = Document() document.$backgoundImage <--- 取得 Publisher 實體 // 而以下如此是做 Bind $document.background

35:28 More Persistence

cloudKit
API 使用

47:26 CoreData
API 使用

@ObservedObject
@FetchRequest

Lecture 14: Document Architecture

  • App and Scene
  • Document Architecture
  • Components of a "document-oriented" app

App Architecture

  • App protocol
  • Scene protocol
    • WindowGroup { }
    • DocumentGroup(newDocument:) { }
    • DocumentGroup(viewing:) { }
  • @SenceStorage
  • @AppStorage
  • @ScaledMetric

7:48 Code

app icon -> Asset.xcassets

19:56 RawRepresentable

每次開啟 app 後 load backgroundImage 完成又去 zoomToFit

28:02 Document Architecture

FileDocument
ReferenceFileDocument
UTType
Document Types
39:05 Undo

func undoablyPerform(operation: String, with undoManager: UndoManager?) { let oldModel = model doIt() undoManager?.registerUndo(withTarget: self) { mySelf in mySelf.model = oldModel } undoManager?.setActionName(operation) }

43:14 Back To Code

  • 49:50 讓 ViewModel conform to ReferenceFileDocument
  • 1:02:16 undo imple
  • 1:12:01 support document

cocoaError(.fileReadCorrup)