Skip to content

Commit 7944e02

Browse files
committed
Add custom expression views; include sample project
1 parent 0cb4432 commit 7944e02

29 files changed

Lines changed: 909 additions & 45 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ fastlane/test_output
8888
# https://github.com/johnno1962/injectionforxcode
8989

9090
iOSInjectionProject/
91+
.DS_Store
92+
/Package.resolved
93+
/Example/PredicateViewExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Example/PredicateViewExample.xcodeproj/project.pbxproj

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

Example/PredicateViewExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "dark"
13+
}
14+
],
15+
"idiom" : "universal",
16+
"platform" : "ios",
17+
"size" : "1024x1024"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "tinted"
24+
}
25+
],
26+
"idiom" : "universal",
27+
"platform" : "ios",
28+
"size" : "1024x1024"
29+
},
30+
{
31+
"idiom" : "mac",
32+
"scale" : "1x",
33+
"size" : "16x16"
34+
},
35+
{
36+
"idiom" : "mac",
37+
"scale" : "2x",
38+
"size" : "16x16"
39+
},
40+
{
41+
"idiom" : "mac",
42+
"scale" : "1x",
43+
"size" : "32x32"
44+
},
45+
{
46+
"idiom" : "mac",
47+
"scale" : "2x",
48+
"size" : "32x32"
49+
},
50+
{
51+
"idiom" : "mac",
52+
"scale" : "1x",
53+
"size" : "128x128"
54+
},
55+
{
56+
"idiom" : "mac",
57+
"scale" : "2x",
58+
"size" : "128x128"
59+
},
60+
{
61+
"idiom" : "mac",
62+
"scale" : "1x",
63+
"size" : "256x256"
64+
},
65+
{
66+
"idiom" : "mac",
67+
"scale" : "2x",
68+
"size" : "256x256"
69+
},
70+
{
71+
"idiom" : "mac",
72+
"scale" : "1x",
73+
"size" : "512x512"
74+
},
75+
{
76+
"idiom" : "mac",
77+
"scale" : "2x",
78+
"size" : "512x512"
79+
}
80+
],
81+
"info" : {
82+
"author" : "xcode",
83+
"version" : 1
84+
}
85+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// ContentView.swift
3+
// PredicateViewExample
4+
//
5+
// Created by Phil Zakharchenko on 9/21/24.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
import PredicateView
11+
12+
struct ContentView: View {
13+
var body: some View {
14+
NavigationSplitView {
15+
List {
16+
NavigationLink("Simple") {
17+
PredicateDemoView()
18+
.navigationTitle("PredicateView")
19+
.toolbarTitleDisplayMode(.inline)
20+
}
21+
22+
NavigationLink("SwiftData") {
23+
SwiftDataDemoView()
24+
.navigationTitle("SwiftData")
25+
.toolbarTitleDisplayMode(.inline)
26+
}
27+
}
28+
#if os(macOS)
29+
.navigationSplitViewColumnWidth(min: 180, ideal: 200)
30+
#endif
31+
} detail: {
32+
Text("Select an item")
33+
}
34+
}
35+
36+
// private func addItem() {
37+
// withAnimation {
38+
// let newItem = Item(timestamp: Date())
39+
// modelContext.insert(newItem)
40+
// }
41+
// }
42+
//
43+
// private func deleteItems(offsets: IndexSet) {
44+
// withAnimation {
45+
// for index in offsets {
46+
// modelContext.delete(items[index])
47+
// }
48+
// }
49+
// }
50+
}
51+
52+
#Preview {
53+
ContentView()
54+
.modelContainer(for: Item.self, inMemory: true)
55+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Item.swift
3+
// PredicateViewExample
4+
//
5+
// Created by Phil Zakharchenko on 9/21/24.
6+
//
7+
8+
import Foundation
9+
import SwiftData
10+
11+
@Model
12+
final class Item {
13+
enum Status: String, CaseIterable, Codable {
14+
case todo, inProgress, done, unknown
15+
}
16+
17+
var id: UUID = UUID()
18+
var timestamp: Date = Date()
19+
var title: String = ""
20+
var _status: Status.RawValue? = nil
21+
22+
init() {
23+
self.id = UUID()
24+
self.timestamp = Date(timeIntervalSinceNow: .random(in: -3600 * 24...3600 * 24))
25+
self.title = "Item \(Int.random(in: 1...1000))"
26+
self._status = Status.allCases.randomElement()!.rawValue
27+
}
28+
29+
var status: Status {
30+
guard let _status, let status = Status(rawValue: _status) else { return .unknown }
31+
return status
32+
}
33+
}

Sources/PredicateView/Views/PredicateDemoView.swift renamed to Example/PredicateViewExample/PredicateDemoView.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import PredicateView
910

1011
public struct PredicateDemoView: View {
1112
struct Model: Identifiable {
@@ -68,18 +69,20 @@ public struct PredicateDemoView: View {
6869

6970
public var body: some View {
7071
VStack(alignment: .leading) {
71-
PredicateView(predicate: $predicate, rowTemplates: [
72-
.init(keyPath: \.firstName, title: "First Name"),
73-
.init(keyPath: \.lastName, title: "Last Name"),
74-
.init(keyPath: \.location, title: "Location"),
75-
.init(keyPath: \.age, title: "Age"),
76-
.init(keyPath: \.employmentStatus, title: "Employment Status"),
77-
.init(keyPath: \.isRegistered, title: "Registration Status"),
78-
.init(keyPath: \.preferredColors, title: "Preferred Colors", rowTemplates: [
79-
.init(keyPath: \.name, title: "Name"),
80-
.init(keyPath: \.cost, title: "Cost"),
72+
ScrollView(.horizontal) {
73+
PredicateView(predicate: $predicate, rowTemplates: [
74+
.init(keyPath: \.firstName, title: "First Name"),
75+
.init(keyPath: \.lastName, title: "Last Name"),
76+
.init(keyPath: \.location, title: "Location"),
77+
.init(keyPath: \.age, title: "Age"),
78+
.init(keyPath: \.employmentStatus, title: "Employment Status"),
79+
.init(keyPath: \.isRegistered, title: "Registration Status"),
80+
.init(keyPath: \.preferredColors, title: "Preferred Colors", rowTemplates: [
81+
.init(keyPath: \.name, title: "Name"),
82+
.init(keyPath: \.cost, title: "Cost"),
83+
])
8184
])
82-
])
85+
}
8386

8487
FilteredResultsTable(predicate: $predicate, data: $data)
8588
}
@@ -104,6 +107,7 @@ public struct PredicateDemoView: View {
104107
}
105108
TableColumn("Registered") { model in
106109
Image(systemName: model.isRegistered ? "checkmark" : "xmark")
110+
.fontWeight(.medium)
107111
}
108112
TableColumn("Preferred Colors") { model in
109113
ScrollView(.horizontal) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.files.user-selected.read-only</key>
8+
<true/>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)