Skip to content

Commit

Permalink
Add playgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Jan 20, 2025
1 parent 84a8331 commit 15d3ce9
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
61 changes: 61 additions & 0 deletions playgrounds/PlayingSwiftUI/PlayingSwiftUI/ContentView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 10 additions & 0 deletions playgrounds/PlayingSwiftUI/PlayingSwiftUI/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>
18 changes: 18 additions & 0 deletions playgrounds/PlayingSwiftUI/PlayingSwiftUI/Item.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array/>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
32 changes: 32 additions & 0 deletions playgrounds/PlayingSwiftUI/PlayingSwiftUI/PlayingSwiftUIApp.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -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.
}

}
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 15d3ce9

Please sign in to comment.