Skip to content

Commit 51eeeef

Browse files
chore: add SwiftUI example app
1 parent f173131 commit 51eeeef

File tree

11 files changed

+825
-0
lines changed

11 files changed

+825
-0
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample.xcodeproj/project.pbxproj

Lines changed: 563 additions & 0 deletions
Large diffs are not rendered by default.
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
"info" : {
32+
"author" : "xcode",
33+
"version" : 1
34+
}
35+
}
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ContentView.swift
3+
// FirebaseSwiftUIExample
4+
//
5+
// Created by Russell Wheatley on 18/02/2025.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
11+
struct ContentView: View {
12+
@Environment(\.modelContext) private var modelContext
13+
@Query private var items: [Item]
14+
15+
var body: some View {
16+
NavigationSplitView {
17+
List {
18+
ForEach(items) { item in
19+
NavigationLink {
20+
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
21+
} label: {
22+
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
23+
}
24+
}
25+
.onDelete(perform: deleteItems)
26+
}
27+
.toolbar {
28+
ToolbarItem(placement: .navigationBarTrailing) {
29+
EditButton()
30+
}
31+
ToolbarItem {
32+
Button(action: addItem) {
33+
Label("Add Item", systemImage: "plus")
34+
}
35+
}
36+
}
37+
} detail: {
38+
Text("Select an item")
39+
}
40+
}
41+
42+
private func addItem() {
43+
withAnimation {
44+
let newItem = Item(timestamp: Date())
45+
modelContext.insert(newItem)
46+
}
47+
}
48+
49+
private func deleteItems(offsets: IndexSet) {
50+
withAnimation {
51+
for index in offsets {
52+
modelContext.delete(items[index])
53+
}
54+
}
55+
}
56+
}
57+
58+
#Preview {
59+
ContentView()
60+
.modelContainer(for: Item.self, inMemory: true)
61+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// FirebaseSwiftUIExampleApp.swift
3+
// FirebaseSwiftUIExample
4+
//
5+
// Created by Russell Wheatley on 18/02/2025.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
11+
@main
12+
struct FirebaseSwiftUIExampleApp: App {
13+
var sharedModelContainer: ModelContainer = {
14+
let schema = Schema([
15+
Item.self,
16+
])
17+
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
18+
19+
do {
20+
return try ModelContainer(for: schema, configurations: [modelConfiguration])
21+
} catch {
22+
fatalError("Could not create ModelContainer: \(error)")
23+
}
24+
}()
25+
26+
var body: some Scene {
27+
WindowGroup {
28+
ContentView()
29+
}
30+
.modelContainer(sharedModelContainer)
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Item.swift
3+
// FirebaseSwiftUIExample
4+
//
5+
// Created by Russell Wheatley on 18/02/2025.
6+
//
7+
8+
import Foundation
9+
import SwiftData
10+
11+
@Model
12+
final class Item {
13+
var timestamp: Date
14+
15+
init(timestamp: Date) {
16+
self.timestamp = timestamp
17+
}
18+
}
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// FirebaseSwiftUIExampleTests.swift
3+
// FirebaseSwiftUIExampleTests
4+
//
5+
// Created by Russell Wheatley on 18/02/2025.
6+
//
7+
8+
import Testing
9+
@testable import FirebaseSwiftUIExample
10+
11+
struct FirebaseSwiftUIExampleTests {
12+
13+
@Test func example() async throws {
14+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
15+
}
16+
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// FirebaseSwiftUIExampleUITests.swift
3+
// FirebaseSwiftUIExampleUITests
4+
//
5+
// Created by Russell Wheatley on 18/02/2025.
6+
//
7+
8+
import XCTest
9+
10+
final class FirebaseSwiftUIExampleUITests: XCTestCase {
11+
12+
override func setUpWithError() throws {
13+
// Put setup code here. This method is called before the invocation of each test method in the class.
14+
15+
// In UI tests it is usually best to stop immediately when a failure occurs.
16+
continueAfterFailure = false
17+
18+
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
19+
}
20+
21+
override func tearDownWithError() throws {
22+
// Put teardown code here. This method is called after the invocation of each test method in the class.
23+
}
24+
25+
@MainActor
26+
func testExample() throws {
27+
// UI tests must launch the application that they test.
28+
let app = XCUIApplication()
29+
app.launch()
30+
31+
// Use XCTAssert and related functions to verify your tests produce the correct results.
32+
}
33+
34+
@MainActor
35+
func testLaunchPerformance() throws {
36+
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
37+
// This measures how long it takes to launch your application.
38+
measure(metrics: [XCTApplicationLaunchMetric()]) {
39+
XCUIApplication().launch()
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)