Selaa lähdekoodia

Initial Commit

afan 1 viikko sitten
commit
b09fd0915e

+ 337
- 0
LotteryTracker.xcodeproj/project.pbxproj Näytä tiedosto

@@ -0,0 +1,337 @@
1
+// !$*UTF8*$!
2
+{
3
+	archiveVersion = 1;
4
+	classes = {
5
+	};
6
+	objectVersion = 77;
7
+	objects = {
8
+
9
+/* Begin PBXFileReference section */
10
+		00CDA5D62F212364003E59B4 /* LotteryTracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LotteryTracker.app; sourceTree = BUILT_PRODUCTS_DIR; };
11
+/* End PBXFileReference section */
12
+
13
+/* Begin PBXFileSystemSynchronizedRootGroup section */
14
+		00CDA5D82F212364003E59B4 /* LotteryTracker */ = {
15
+			isa = PBXFileSystemSynchronizedRootGroup;
16
+			path = LotteryTracker;
17
+			sourceTree = "<group>";
18
+		};
19
+/* End PBXFileSystemSynchronizedRootGroup section */
20
+
21
+/* Begin PBXFrameworksBuildPhase section */
22
+		00CDA5D32F212364003E59B4 /* Frameworks */ = {
23
+			isa = PBXFrameworksBuildPhase;
24
+			buildActionMask = 2147483647;
25
+			files = (
26
+			);
27
+			runOnlyForDeploymentPostprocessing = 0;
28
+		};
29
+/* End PBXFrameworksBuildPhase section */
30
+
31
+/* Begin PBXGroup section */
32
+		00CDA5CD2F212364003E59B4 = {
33
+			isa = PBXGroup;
34
+			children = (
35
+				00CDA5D82F212364003E59B4 /* LotteryTracker */,
36
+				00CDA5D72F212364003E59B4 /* Products */,
37
+			);
38
+			sourceTree = "<group>";
39
+		};
40
+		00CDA5D72F212364003E59B4 /* Products */ = {
41
+			isa = PBXGroup;
42
+			children = (
43
+				00CDA5D62F212364003E59B4 /* LotteryTracker.app */,
44
+			);
45
+			name = Products;
46
+			sourceTree = "<group>";
47
+		};
48
+/* End PBXGroup section */
49
+
50
+/* Begin PBXNativeTarget section */
51
+		00CDA5D52F212364003E59B4 /* LotteryTracker */ = {
52
+			isa = PBXNativeTarget;
53
+			buildConfigurationList = 00CDA5E62F212367003E59B4 /* Build configuration list for PBXNativeTarget "LotteryTracker" */;
54
+			buildPhases = (
55
+				00CDA5D22F212364003E59B4 /* Sources */,
56
+				00CDA5D32F212364003E59B4 /* Frameworks */,
57
+				00CDA5D42F212364003E59B4 /* Resources */,
58
+			);
59
+			buildRules = (
60
+			);
61
+			dependencies = (
62
+			);
63
+			fileSystemSynchronizedGroups = (
64
+				00CDA5D82F212364003E59B4 /* LotteryTracker */,
65
+			);
66
+			name = LotteryTracker;
67
+			packageProductDependencies = (
68
+			);
69
+			productName = LotteryTracker;
70
+			productReference = 00CDA5D62F212364003E59B4 /* LotteryTracker.app */;
71
+			productType = "com.apple.product-type.application";
72
+		};
73
+/* End PBXNativeTarget section */
74
+
75
+/* Begin PBXProject section */
76
+		00CDA5CE2F212364003E59B4 /* Project object */ = {
77
+			isa = PBXProject;
78
+			attributes = {
79
+				BuildIndependentTargetsInParallel = 1;
80
+				LastSwiftUpdateCheck = 2620;
81
+				LastUpgradeCheck = 2620;
82
+				TargetAttributes = {
83
+					00CDA5D52F212364003E59B4 = {
84
+						CreatedOnToolsVersion = 26.2;
85
+					};
86
+				};
87
+			};
88
+			buildConfigurationList = 00CDA5D12F212364003E59B4 /* Build configuration list for PBXProject "LotteryTracker" */;
89
+			developmentRegion = en;
90
+			hasScannedForEncodings = 0;
91
+			knownRegions = (
92
+				en,
93
+				Base,
94
+			);
95
+			mainGroup = 00CDA5CD2F212364003E59B4;
96
+			minimizedProjectReferenceProxies = 1;
97
+			preferredProjectObjectVersion = 77;
98
+			productRefGroup = 00CDA5D72F212364003E59B4 /* Products */;
99
+			projectDirPath = "";
100
+			projectRoot = "";
101
+			targets = (
102
+				00CDA5D52F212364003E59B4 /* LotteryTracker */,
103
+			);
104
+		};
105
+/* End PBXProject section */
106
+
107
+/* Begin PBXResourcesBuildPhase section */
108
+		00CDA5D42F212364003E59B4 /* Resources */ = {
109
+			isa = PBXResourcesBuildPhase;
110
+			buildActionMask = 2147483647;
111
+			files = (
112
+			);
113
+			runOnlyForDeploymentPostprocessing = 0;
114
+		};
115
+/* End PBXResourcesBuildPhase section */
116
+
117
+/* Begin PBXSourcesBuildPhase section */
118
+		00CDA5D22F212364003E59B4 /* Sources */ = {
119
+			isa = PBXSourcesBuildPhase;
120
+			buildActionMask = 2147483647;
121
+			files = (
122
+			);
123
+			runOnlyForDeploymentPostprocessing = 0;
124
+		};
125
+/* End PBXSourcesBuildPhase section */
126
+
127
+/* Begin XCBuildConfiguration section */
128
+		00CDA5E42F212367003E59B4 /* Debug */ = {
129
+			isa = XCBuildConfiguration;
130
+			buildSettings = {
131
+				ALWAYS_SEARCH_USER_PATHS = NO;
132
+				ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
133
+				CLANG_ANALYZER_NONNULL = YES;
134
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
135
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
136
+				CLANG_ENABLE_MODULES = YES;
137
+				CLANG_ENABLE_OBJC_ARC = YES;
138
+				CLANG_ENABLE_OBJC_WEAK = YES;
139
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
140
+				CLANG_WARN_BOOL_CONVERSION = YES;
141
+				CLANG_WARN_COMMA = YES;
142
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
143
+				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
144
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
145
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
146
+				CLANG_WARN_EMPTY_BODY = YES;
147
+				CLANG_WARN_ENUM_CONVERSION = YES;
148
+				CLANG_WARN_INFINITE_RECURSION = YES;
149
+				CLANG_WARN_INT_CONVERSION = YES;
150
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
151
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
152
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
153
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
154
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
155
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
156
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
157
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
158
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
159
+				CLANG_WARN_UNREACHABLE_CODE = YES;
160
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
161
+				COPY_PHASE_STRIP = NO;
162
+				DEBUG_INFORMATION_FORMAT = dwarf;
163
+				DEVELOPMENT_TEAM = 85DNK99BC3;
164
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
165
+				ENABLE_TESTABILITY = YES;
166
+				ENABLE_USER_SCRIPT_SANDBOXING = YES;
167
+				GCC_C_LANGUAGE_STANDARD = gnu17;
168
+				GCC_DYNAMIC_NO_PIC = NO;
169
+				GCC_NO_COMMON_BLOCKS = YES;
170
+				GCC_OPTIMIZATION_LEVEL = 0;
171
+				GCC_PREPROCESSOR_DEFINITIONS = (
172
+					"DEBUG=1",
173
+					"$(inherited)",
174
+				);
175
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
176
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
177
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
178
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
179
+				GCC_WARN_UNUSED_FUNCTION = YES;
180
+				GCC_WARN_UNUSED_VARIABLE = YES;
181
+				IPHONEOS_DEPLOYMENT_TARGET = 26.2;
182
+				LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
183
+				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
184
+				MTL_FAST_MATH = YES;
185
+				ONLY_ACTIVE_ARCH = YES;
186
+				SDKROOT = iphoneos;
187
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
188
+				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
189
+			};
190
+			name = Debug;
191
+		};
192
+		00CDA5E52F212367003E59B4 /* Release */ = {
193
+			isa = XCBuildConfiguration;
194
+			buildSettings = {
195
+				ALWAYS_SEARCH_USER_PATHS = NO;
196
+				ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
197
+				CLANG_ANALYZER_NONNULL = YES;
198
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
199
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
200
+				CLANG_ENABLE_MODULES = YES;
201
+				CLANG_ENABLE_OBJC_ARC = YES;
202
+				CLANG_ENABLE_OBJC_WEAK = YES;
203
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
204
+				CLANG_WARN_BOOL_CONVERSION = YES;
205
+				CLANG_WARN_COMMA = YES;
206
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
207
+				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
208
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
209
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
210
+				CLANG_WARN_EMPTY_BODY = YES;
211
+				CLANG_WARN_ENUM_CONVERSION = YES;
212
+				CLANG_WARN_INFINITE_RECURSION = YES;
213
+				CLANG_WARN_INT_CONVERSION = YES;
214
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
215
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
216
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
217
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
218
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
219
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
220
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
221
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
222
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
223
+				CLANG_WARN_UNREACHABLE_CODE = YES;
224
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
225
+				COPY_PHASE_STRIP = NO;
226
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
227
+				DEVELOPMENT_TEAM = 85DNK99BC3;
228
+				ENABLE_NS_ASSERTIONS = NO;
229
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
230
+				ENABLE_USER_SCRIPT_SANDBOXING = YES;
231
+				GCC_C_LANGUAGE_STANDARD = gnu17;
232
+				GCC_NO_COMMON_BLOCKS = YES;
233
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
234
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
235
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
236
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
237
+				GCC_WARN_UNUSED_FUNCTION = YES;
238
+				GCC_WARN_UNUSED_VARIABLE = YES;
239
+				IPHONEOS_DEPLOYMENT_TARGET = 26.2;
240
+				LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
241
+				MTL_ENABLE_DEBUG_INFO = NO;
242
+				MTL_FAST_MATH = YES;
243
+				SDKROOT = iphoneos;
244
+				SWIFT_COMPILATION_MODE = wholemodule;
245
+				VALIDATE_PRODUCT = YES;
246
+			};
247
+			name = Release;
248
+		};
249
+		00CDA5E72F212367003E59B4 /* Debug */ = {
250
+			isa = XCBuildConfiguration;
251
+			buildSettings = {
252
+				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
253
+				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
254
+				CODE_SIGN_STYLE = Automatic;
255
+				CURRENT_PROJECT_VERSION = 1;
256
+				DEVELOPMENT_TEAM = 85DNK99BC3;
257
+				ENABLE_PREVIEWS = YES;
258
+				GENERATE_INFOPLIST_FILE = YES;
259
+				INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
260
+				INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
261
+				INFOPLIST_KEY_UILaunchScreen_Generation = YES;
262
+				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
263
+				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
264
+				LD_RUNPATH_SEARCH_PATHS = (
265
+					"$(inherited)",
266
+					"@executable_path/Frameworks",
267
+				);
268
+				MARKETING_VERSION = 1.0;
269
+				PRODUCT_BUNDLE_IDENTIFIER = top.afanai.LotteryTracker;
270
+				PRODUCT_NAME = "$(TARGET_NAME)";
271
+				STRING_CATALOG_GENERATE_SYMBOLS = YES;
272
+				SWIFT_APPROACHABLE_CONCURRENCY = YES;
273
+				SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor;
274
+				SWIFT_EMIT_LOC_STRINGS = YES;
275
+				SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
276
+				SWIFT_VERSION = 5.0;
277
+				TARGETED_DEVICE_FAMILY = "1,2";
278
+			};
279
+			name = Debug;
280
+		};
281
+		00CDA5E82F212367003E59B4 /* Release */ = {
282
+			isa = XCBuildConfiguration;
283
+			buildSettings = {
284
+				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
285
+				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
286
+				CODE_SIGN_STYLE = Automatic;
287
+				CURRENT_PROJECT_VERSION = 1;
288
+				DEVELOPMENT_TEAM = 85DNK99BC3;
289
+				ENABLE_PREVIEWS = YES;
290
+				GENERATE_INFOPLIST_FILE = YES;
291
+				INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
292
+				INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
293
+				INFOPLIST_KEY_UILaunchScreen_Generation = YES;
294
+				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
295
+				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
296
+				LD_RUNPATH_SEARCH_PATHS = (
297
+					"$(inherited)",
298
+					"@executable_path/Frameworks",
299
+				);
300
+				MARKETING_VERSION = 1.0;
301
+				PRODUCT_BUNDLE_IDENTIFIER = top.afanai.LotteryTracker;
302
+				PRODUCT_NAME = "$(TARGET_NAME)";
303
+				STRING_CATALOG_GENERATE_SYMBOLS = YES;
304
+				SWIFT_APPROACHABLE_CONCURRENCY = YES;
305
+				SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor;
306
+				SWIFT_EMIT_LOC_STRINGS = YES;
307
+				SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
308
+				SWIFT_VERSION = 5.0;
309
+				TARGETED_DEVICE_FAMILY = "1,2";
310
+			};
311
+			name = Release;
312
+		};
313
+/* End XCBuildConfiguration section */
314
+
315
+/* Begin XCConfigurationList section */
316
+		00CDA5D12F212364003E59B4 /* Build configuration list for PBXProject "LotteryTracker" */ = {
317
+			isa = XCConfigurationList;
318
+			buildConfigurations = (
319
+				00CDA5E42F212367003E59B4 /* Debug */,
320
+				00CDA5E52F212367003E59B4 /* Release */,
321
+			);
322
+			defaultConfigurationIsVisible = 0;
323
+			defaultConfigurationName = Release;
324
+		};
325
+		00CDA5E62F212367003E59B4 /* Build configuration list for PBXNativeTarget "LotteryTracker" */ = {
326
+			isa = XCConfigurationList;
327
+			buildConfigurations = (
328
+				00CDA5E72F212367003E59B4 /* Debug */,
329
+				00CDA5E82F212367003E59B4 /* Release */,
330
+			);
331
+			defaultConfigurationIsVisible = 0;
332
+			defaultConfigurationName = Release;
333
+		};
334
+/* End XCConfigurationList section */
335
+	};
336
+	rootObject = 00CDA5CE2F212364003E59B4 /* Project object */;
337
+}

+ 7
- 0
LotteryTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata Näytä tiedosto

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<Workspace
3
+   version = "1.0">
4
+   <FileRef
5
+      location = "self:">
6
+   </FileRef>
7
+</Workspace>

+ 14
- 0
LotteryTracker.xcodeproj/xcuserdata/aaa.xcuserdatad/xcschemes/xcschememanagement.plist Näytä tiedosto

@@ -0,0 +1,14 @@
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>SchemeUserState</key>
6
+	<dict>
7
+		<key>LotteryTracker.xcscheme_^#shared#^_</key>
8
+		<dict>
9
+			<key>orderHint</key>
10
+			<integer>0</integer>
11
+		</dict>
12
+	</dict>
13
+</dict>
14
+</plist>

+ 11
- 0
LotteryTracker/Assets.xcassets/AccentColor.colorset/Contents.json Näytä tiedosto

@@ -0,0 +1,11 @@
1
+{
2
+  "colors" : [
3
+    {
4
+      "idiom" : "universal"
5
+    }
6
+  ],
7
+  "info" : {
8
+    "author" : "xcode",
9
+    "version" : 1
10
+  }
11
+}

+ 35
- 0
LotteryTracker/Assets.xcassets/AppIcon.appiconset/Contents.json Näytä tiedosto

@@ -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
+}

+ 6
- 0
LotteryTracker/Assets.xcassets/Contents.json Näytä tiedosto

@@ -0,0 +1,6 @@
1
+{
2
+  "info" : {
3
+    "author" : "xcode",
4
+    "version" : 1
5
+  }
6
+}

+ 86
- 0
LotteryTracker/ContentView.swift Näytä tiedosto

@@ -0,0 +1,86 @@
1
+//
2
+//  ContentView.swift
3
+//  LotteryTracker
4
+//
5
+//  Created by aaa on 2026/1/21.
6
+//
7
+
8
+import SwiftUI
9
+import CoreData
10
+
11
+struct ContentView: View {
12
+    @Environment(\.managedObjectContext) private var viewContext
13
+
14
+    @FetchRequest(
15
+        sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
16
+        animation: .default)
17
+    private var items: FetchedResults<Item>
18
+
19
+    var body: some View {
20
+        NavigationView {
21
+            List {
22
+                ForEach(items) { item in
23
+                    NavigationLink {
24
+                        Text("Item at \(item.timestamp!, formatter: itemFormatter)")
25
+                    } label: {
26
+                        Text(item.timestamp!, formatter: itemFormatter)
27
+                    }
28
+                }
29
+                .onDelete(perform: deleteItems)
30
+            }
31
+            .toolbar {
32
+                ToolbarItem(placement: .navigationBarTrailing) {
33
+                    EditButton()
34
+                }
35
+                ToolbarItem {
36
+                    Button(action: addItem) {
37
+                        Label("Add Item", systemImage: "plus")
38
+                    }
39
+                }
40
+            }
41
+            Text("Select an item")
42
+        }
43
+    }
44
+
45
+    private func addItem() {
46
+        withAnimation {
47
+            let newItem = Item(context: viewContext)
48
+            newItem.timestamp = Date()
49
+
50
+            do {
51
+                try viewContext.save()
52
+            } catch {
53
+                // Replace this implementation with code to handle the error appropriately.
54
+                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
55
+                let nsError = error as NSError
56
+                fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
57
+            }
58
+        }
59
+    }
60
+
61
+    private func deleteItems(offsets: IndexSet) {
62
+        withAnimation {
63
+            offsets.map { items[$0] }.forEach(viewContext.delete)
64
+
65
+            do {
66
+                try viewContext.save()
67
+            } catch {
68
+                // Replace this implementation with code to handle the error appropriately.
69
+                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
70
+                let nsError = error as NSError
71
+                fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
72
+            }
73
+        }
74
+    }
75
+}
76
+
77
+private let itemFormatter: DateFormatter = {
78
+    let formatter = DateFormatter()
79
+    formatter.dateStyle = .short
80
+    formatter.timeStyle = .medium
81
+    return formatter
82
+}()
83
+
84
+#Preview {
85
+    ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
86
+}

+ 8
- 0
LotteryTracker/LotteryTracker.xcdatamodeld/.xccurrentversion Näytä tiedosto

@@ -0,0 +1,8 @@
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>_XCCurrentVersionName</key>
6
+	<string>LotteryTracker.xcdatamodel</string>
7
+</dict>
8
+</plist>

+ 9
- 0
LotteryTracker/LotteryTracker.xcdatamodeld/LotteryTracker.xcdatamodel/contents Näytä tiedosto

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="false" userDefinedModelVersionIdentifier="">
3
+    <entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class">
4
+        <attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
5
+    </entity>
6
+    <elements>
7
+        <element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
8
+    </elements>
9
+</model>

+ 21
- 0
LotteryTracker/LotteryTrackerApp.swift Näytä tiedosto

@@ -0,0 +1,21 @@
1
+//
2
+//  LotteryTrackerApp.swift
3
+//  LotteryTracker
4
+//
5
+//  Created by aaa on 2026/1/21.
6
+//
7
+
8
+import SwiftUI
9
+import CoreData
10
+
11
+@main
12
+struct LotteryTrackerApp: App {
13
+    let persistenceController = PersistenceController.shared
14
+
15
+    var body: some Scene {
16
+        WindowGroup {
17
+            ContentView()
18
+                .environment(\.managedObjectContext, persistenceController.container.viewContext)
19
+        }
20
+    }
21
+}

+ 57
- 0
LotteryTracker/Persistence.swift Näytä tiedosto

@@ -0,0 +1,57 @@
1
+//
2
+//  Persistence.swift
3
+//  LotteryTracker
4
+//
5
+//  Created by aaa on 2026/1/21.
6
+//
7
+
8
+import CoreData
9
+
10
+struct PersistenceController {
11
+    static let shared = PersistenceController()
12
+
13
+    @MainActor
14
+    static let preview: PersistenceController = {
15
+        let result = PersistenceController(inMemory: true)
16
+        let viewContext = result.container.viewContext
17
+        for _ in 0..<10 {
18
+            let newItem = Item(context: viewContext)
19
+            newItem.timestamp = Date()
20
+        }
21
+        do {
22
+            try viewContext.save()
23
+        } catch {
24
+            // Replace this implementation with code to handle the error appropriately.
25
+            // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
26
+            let nsError = error as NSError
27
+            fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
28
+        }
29
+        return result
30
+    }()
31
+
32
+    let container: NSPersistentContainer
33
+
34
+    init(inMemory: Bool = false) {
35
+        container = NSPersistentContainer(name: "LotteryTracker")
36
+        if inMemory {
37
+            container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
38
+        }
39
+        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
40
+            if let error = error as NSError? {
41
+                // Replace this implementation with code to handle the error appropriately.
42
+                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
43
+
44
+                /*
45
+                 Typical reasons for an error here include:
46
+                 * The parent directory does not exist, cannot be created, or disallows writing.
47
+                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
48
+                 * The device is out of space.
49
+                 * The store could not be migrated to the current model version.
50
+                 Check the error message to determine what the actual problem was.
51
+                 */
52
+                fatalError("Unresolved error \(error), \(error.userInfo)")
53
+            }
54
+        })
55
+        container.viewContext.automaticallyMergesChangesFromParent = true
56
+    }
57
+}