From 15d3ce9262d141cd978cf313d511dc81757573b5 Mon Sep 17 00:00:00 2001 From: Muukii Date: Mon, 20 Jan 2025 13:53:27 +0900 Subject: [PATCH] Add playgrounds --- .../AccentColor.colorset/Contents.json | 11 ++++ .../AppIcon.appiconset/Contents.json | 35 +++++++++++ .../Assets.xcassets/Contents.json | 6 ++ .../PlayingSwiftUI/ContentView.swift | 61 +++++++++++++++++++ .../PlayingSwiftUI/PlayingSwiftUI/Info.plist | 10 +++ .../PlayingSwiftUI/PlayingSwiftUI/Item.swift | 18 ++++++ .../PlayingSwiftUI.entitlements | 18 ++++++ .../PlayingSwiftUI/PlayingSwiftUIApp.swift | 32 ++++++++++ .../Preview Assets.xcassets/Contents.json | 6 ++ .../PlayingSwiftUITests.swift | 17 ++++++ .../PlayingSwiftUIUITests.swift | 43 +++++++++++++ .../PlayingSwiftUIUITestsLaunchTests.swift | 33 ++++++++++ 12 files changed, 290 insertions(+) create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/Contents.json create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/ContentView.swift create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Info.plist create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Item.swift create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUI.entitlements create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUIApp.swift create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUITests/PlayingSwiftUITests.swift create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITests.swift create mode 100644 playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITestsLaunchTests.swift diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000000..eb87897008 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..2305880107 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/Contents.json b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..73c00596a7 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/ContentView.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/ContentView.swift new file mode 100644 index 0000000000..1d1b395140 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/ContentView.swift @@ -0,0 +1,61 @@ +// +// ContentView.swift +// PlayingSwiftUI +// +// Created by Muukii on 2025/01/20. +// + +import SwiftUI +import SwiftData + +struct ContentView: View { + @Environment(\.modelContext) private var modelContext + @Query private var items: [Item] + + var body: some View { + NavigationSplitView { + List { + ForEach(items) { item in + NavigationLink { + Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))") + } label: { + Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard)) + } + } + .onDelete(perform: deleteItems) + } + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + EditButton() + } + ToolbarItem { + Button(action: addItem) { + Label("Add Item", systemImage: "plus") + } + } + } + } detail: { + Text("Select an item") + } + } + + private func addItem() { + withAnimation { + let newItem = Item(timestamp: Date()) + modelContext.insert(newItem) + } + } + + private func deleteItems(offsets: IndexSet) { + withAnimation { + for index in offsets { + modelContext.delete(items[index]) + } + } + } +} + +#Preview { + ContentView() + .modelContainer(for: Item.self, inMemory: true) +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Info.plist b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Info.plist new file mode 100644 index 0000000000..ca9a074acb --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Info.plist @@ -0,0 +1,10 @@ + + + + + UIBackgroundModes + + remote-notification + + + diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Item.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Item.swift new file mode 100644 index 0000000000..af92f1e29e --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Item.swift @@ -0,0 +1,18 @@ +// +// Item.swift +// PlayingSwiftUI +// +// Created by Muukii on 2025/01/20. +// + +import Foundation +import SwiftData + +@Model +final class Item { + var timestamp: Date + + init(timestamp: Date) { + self.timestamp = timestamp + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUI.entitlements b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUI.entitlements new file mode 100644 index 0000000000..cbd408ec30 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUI.entitlements @@ -0,0 +1,18 @@ + + + + + aps-environment + development + com.apple.developer.icloud-container-identifiers + + com.apple.developer.icloud-services + + CloudKit + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUIApp.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUIApp.swift new file mode 100644 index 0000000000..10c8007167 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUIApp.swift @@ -0,0 +1,32 @@ +// +// PlayingSwiftUIApp.swift +// PlayingSwiftUI +// +// Created by Muukii on 2025/01/20. +// + +import SwiftUI +import SwiftData + +@main +struct PlayingSwiftUIApp: App { + var sharedModelContainer: ModelContainer = { + let schema = Schema([ + Item.self, + ]) + let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) + + do { + return try ModelContainer(for: schema, configurations: [modelConfiguration]) + } catch { + fatalError("Could not create ModelContainer: \(error)") + } + }() + + var body: some Scene { + WindowGroup { + ContentView() + } + .modelContainer(sharedModelContainer) + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000000..73c00596a7 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUITests/PlayingSwiftUITests.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUITests/PlayingSwiftUITests.swift new file mode 100644 index 0000000000..b52747d53b --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUITests/PlayingSwiftUITests.swift @@ -0,0 +1,17 @@ +// +// PlayingSwiftUITests.swift +// PlayingSwiftUITests +// +// Created by Muukii on 2025/01/20. +// + +import Testing +@testable import PlayingSwiftUI + +struct PlayingSwiftUITests { + + @Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + } + +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITests.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITests.swift new file mode 100644 index 0000000000..c2dc8d0aac --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITests.swift @@ -0,0 +1,43 @@ +// +// PlayingSwiftUIUITests.swift +// PlayingSwiftUIUITests +// +// Created by Muukii on 2025/01/20. +// + +import XCTest + +final class PlayingSwiftUIUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // 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. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + @MainActor + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + @MainActor + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITestsLaunchTests.swift b/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITestsLaunchTests.swift new file mode 100644 index 0000000000..e6decbc005 --- /dev/null +++ b/playgrounds/PlayingSwiftUI/PlayingSwiftUIUITests/PlayingSwiftUIUITestsLaunchTests.swift @@ -0,0 +1,33 @@ +// +// PlayingSwiftUIUITestsLaunchTests.swift +// PlayingSwiftUIUITests +// +// Created by Muukii on 2025/01/20. +// + +import XCTest + +final class PlayingSwiftUIUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + @MainActor + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +}