Slide 1

Slide 1 text

題: 場所: 日付: 0VUMJOF7JFXJO4XJGU6* NBD04OBUJWF4ZNQPTJVN ೥݄೔ KQ 発表者:

Slide 2

Slide 2 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp /40VUMJOF7JFX

Slide 3

Slide 3 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp ࣗݾ঺հ CotEditor Gapplin Qli application works plain-text editor SVG viewer movie player macOS meet-up icon works @1024jp hobby macOS developer/designer

Slide 4

Slide 4 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp $PU&EJUPS CotEditor plain-text editor for macOS

Slide 5

Slide 5 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXJO$PU&EJUPS final class FileNode { enum Kind { case folder case general case archive case ... } let isDirectory: Bool private(set) var name: String private(set) var kind: Kind private(set) var isHidden: Bool ... private(set) var fileURL: URL private(set) weak var parent: FileNode? private var cachedChildren: [FileNode]? var children: [FileNode]? { if self.cachedChildren == nil, self.isDirectory { self.cachedChildren = try? self.readChildren() } return self.cachedChildren } }

Slide 6

Slide 6 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXJO$PU&EJUPS

Slide 7

Slide 7 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXͷྺ࢙ Outline View Programming TopicsΑΓ https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/OutlineView/OutlineView.html#//apple_ref/doc/uid/10000023i

Slide 8

Slide 8 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXͷྺ࢙ ZFBS 04 0VUMJOF7JFXؔ࿈ٕज़ ΄͔τϐοΫ 0QFO4UFQ /45BCMF7JFX ʜ .BD049 /40VUMJOF7JFX 0VUMJOF7JFX1SPHSBNNJOH5PQJDT .BD049 $PDPB#JOEJOH .BD049 /45SFF$POUSPMMFS .BD049 /40VUMJOF7JFX%FMFHBUF %BUB4PVSDFϓϩτίϧԽ .BD049 WJFXCBTFEUBCMF ʜ NBD04 4XJGU6* NBD04 4XJGU6*γϯάϧΧϥϜPVUMJOFWJFX NBD04 4XJGU6*ϚϧνΧϥϜPVUMJOFWJFX SwiftUI࣌୅ʁʁ

Slide 9

Slide 9 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXJO4XJGU6* -JTU 5BCMF બ΂Δछྨͷ࣮૷ʂ github.com/1024jp/OutlineApp 1024jp/OutlineApp

Slide 10

Slide 10 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXJO4XJGU6* List($items) { item in ForEach($items) { item in RowView(item: item) } } Table(of: Binding.self) { item in TableColumn("Name") { TextField(text: item.name, label: EmptyView.init) } } rows: { RecursiveTableRows(items: $items) } List($items, children: \.children) { item in TextField(text: item.name, label: EmptyView.init) } List { OutlineGroup($items, children: \.children) { item in TextField(text: item.name, label: EmptyView.init) } } Table(self.items, children: \.children) { item in TableColumn("Name", value: \.name) { Text(item.name) } } -JTUܥ 5BCMFܥ private struct RowView: View { @Binding var item: Item var body: some View { if let children = Binding<[Item]>($item.children) { DisclosureGroup(isExpanded: $item.isExpanded) { ForEach(children) { child in RowView(item: child) } } label: { TextField(text: $item.name, label: EmptyView.init) } } else { TextField(text: $item.name, label: EmptyView.init) } } } private struct RecursiveTableRows: TableRowContent { @Binding var items: [Item] var tableRowBody: some TableRowContent> { ForEach($items) { item in if let children = Binding(item.children) { DisclosureTableRow(item, isExpanded: item.isExpanded) { RecursiveTableRows(children) } } else { TableRow(item) } } } }

Slide 11

Slide 11 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp 0VUMJOF7JFXJO4XJGU6* NSOutlineView List Table children disclosure OutlineGroup children disclosure available macOS 10.0 macOS 12 macOS 12 macOS 11 macOS 14 macOS 14 ηΫγϣϯϔομ Section ✔︎ × ✔︎ ✔︎ × ✔︎ ฤू @Binding ✔︎ ✔︎ ✔︎ ✔︎ × ✔︎ ։ด੍ޚ isExpanded ✔︎ × ✔︎ × × ✔︎ D&Dιʔτ ✔︎ × △ × × △ ΧϥϜΧελϚΠζ columnCustomization ✔︎ ✔︎ ✔︎ ΧϥϜιʔτ sortOrder ✔︎ ✔︎ ✔︎ ʢཁखಈΩϟετʣ

Slide 12

Slide 12 text

macOS native 0VUMJOF7JFXJO4XJGU6* ©2024 1024jp %SBH%SPQ "1* ڍಈ ෆ౎߹ ForEach() { ... }.onMove(perform:) ҠಈݩͷSPXͷIndexSet͕ಘΒΕΔ r ಉҰ֊૚಺ͷҠಈʹ͔͠࢖͑ͳ͍ onDrop(of:delegate:) %FMFHBUFͰΠϕϯτผͷॲཧΛ ࡉ੍͔͘ޚͰ͖Δ ʢNSTableViewDelegateʹ͍ۙʣ r 伱ؒʹೖΕΒΕͳ͍ r ෳ਺߲໨͕υϩοϓ͞ΕΔ͜ͱΛߟྀ͍ͯ͠ͳ͍ onDrop(of:perform:) onInsert(of:perform:) [NSItemProvider]͕ಘΒΕΔ [NSItemProvider]ͱIndex͕ ಘΒΕΔ r υϩοϓͰඞͣ ➕ϚʔΫ͕ग़Δ dropDestination( for:action:) ࣗ਎ͷҠಈ [any Transferable]͕ಘΒΕΔ 成功事例待ってます!! r ԿΕʹͤΑɺʮΰϛശ΁υϩοϓʯͳΜ͔͕͕Ͱ͖ͳ͍

Slide 13

Slide 13 text

©2024 1024jp macOS native 0VUMJOF7JFXJO4XJGU6* ͓ΘΓ