Swift Playground

RSS for tag

Learn and explore coding in Swift through interactive learning experiences on the Swift Playground app for iPadOS and macOS.

Posts under Swift Playground tag

59 Posts

Post

Replies

Boosts

Views

Activity

Updating Apps on the AppStore no longer working for me.
I have been using Swift Playground to build and submit my apps to the appstore for around three years now. Recently I uploaded two of my apps but now when I submit them for approval an error is issued… “Unable to Add for Review”… (see pic attached). I don’t understand it because Playground does not use Xcode as far as I am aware? Can someone advise me what I can do to resolve this? Is it something I have to wait to be fixed by an Apple update?
1
0
68
2d
On iPad with Swift Playgrounds: How to open chapter as a playground?
Note On a Mac with Xcode installed, or on an iPad with Swift Playgrounds, you can open this chapter as a playground. Playgrounds allow you to edit the code listings and see the results immediately. (Note in page 3) (I would like to open the chapter or book: Swift Programming Language in Swift Playground on iPad) https://books.apple.com/ve/book/the-swift-programming-language-swift-5-7-beta/id1002622538?l=en-GB Best regards
1
0
706
1w
Swift Playgrounds Incompatibility with Xcode 16 Files and Swift Versions
I'm facing an issue with Swift Playgrounds and files created in Xcode 16. It seems that Swift Playgrounds does not support Swift 6, but even when I create files specifically with Swift 5, Swift Playgrounds still reports that the files are unsupported. This creates a significant problem because macOS Sequoia does not allow me to revert to Xcode 15, which might have offered better compatibility. As it stands, I can't find a solution to work seamlessly between Xcode and Swift Playgrounds. Has anyone else encountered this issue? Are there any workarounds or updates planned to address this compatibility gap? Any advice would be greatly appreciated!
6
2
1.2k
2w
Reoccurring data access prompt issue with Swift Playgrounds 4.6.4 on macOS 26.1
Hello, I am having a recurring issue using Swift Playgrounds version 4.6.4 on macOS 26.1. Upon opening a file and every other time I start typing in the code section I get a prompt, the image below, two or three times. It doesn't matter if I accept or decline all or some of the prompts, as soon as I start typing on another line I get prompted another two or three times for permission. It appears to me that prompt generates every time the preview pane tries to update. Declining the prompt breaks the preview but accepting the prompt only gets you through a single line of code before it appears again. I believe this issue started after I updated to macOS26.1 as I had not encountered it before. I've also opened other files with Swift Playgrounds and encounter the same problem. It could also be unrelated to the update and could be an issue with some permission setting somewhere, however, I have been unable to find what or where it could be. Is anyone else experiencing this? Thank you for your time :)
28
19
2.7k
2w
Can I withdraw my submission and resubmit an updated playground?
Hello everyone, I have already submitted my app playground for the Swift Student Challenge. After submission I noticed a few things I would like to improve and fix. Is it possible to withdraw my current submission and then immediately resubmit an updated version? Any clarification (especially from Apple staff or anyone who has done this before) would be very helpful. Thank you!
1
0
273
Feb ’26
“Keep Going with Apps” Tutorial section will not complete.
Hello All, I am currently working through ”Keep going with Apps” in Swift Playground. The section in the tutorial “Add a DancingCreature view” will not complete. I have tried to type it is as written in the tutorial and even used the copy and paste button provided. I have restarted the app and my IPad with no success. I have attached a screen shot of the tutorial prompt. Here is the code block: import SwiftUI import Guide struct DancingCreatures: View { //#-learning-code-snippet(varDeclaration) @EnvironmentObject var data : CreatureZoo var body: some View { SPCAssessableGroup(view: self) { VStack { ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ } } ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ //#-learning-code-snippet(exp1) //#-learning-code-snippet(animationSolution) //#-learning-code-snippet(exp3) } } /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ } } } } struct DancingCreatures_Previews: PreviewProvider { static var previews: some View { DancingCreatures().environmentObject(CreatureZoo()) } } Device information: IPad Pro (11 inch, 2nd gen) iPad OS Version: 26.0.1 Playground Version: 4.6.4 Anyone else come across this? Thank you in advance.
7
6
724
Feb ’26
Are Xcode warnings like this safe to submit (won’t disqualify)?
I’m building a Swift Playgrounds app (.swiftpm) in Xcode 26.2 and I consistently see this warning, even on brand-new Swift Playgrounds apps created from the default template: “Skipping duplicate build file in Compile Sources build phase: /Users/.../.swiftpm/Media.xcassets” Everything builds and runs normally and all images/assets appear correctly, so it seems like it’s just an annoying warning. I’ve checked for duplicates and don’t see the asset catalog listed twice, but the warning still appears whenever I add an asset catalog to any playground project in Xcode. Is this warning safe to ignore for submission, and it won’t affect Swift Student Challenge eligibility?
5
0
340
Feb ’26
Xcode Playground and FoundationModels
I am trying to test FoundationModels in a Swift Playground in Xcode 26.2, macOS 26.3, and am running into an issue. The following simple code generates an error: import FoundationModels @Generable struct Specifications { @Guide(description: "Search for color") var color: String } I see the following error message in the console: error: AIPlayground.playground:4:8: external macro implementation type 'FoundationModelsMacros.GenerableMacro' could not be found for macro 'Generable(description:)'; plugin for module 'FoundationModelsMacros' not found The Xcode editor does not appear to recognize the @Generable or @Guide macros, despite importing FoundationModels. What step/setting am I missing?
2
0
152
Feb ’26
What Xcode version will be used for SSC evaluation?
Hello! Because the compilers used by different versions of Xcode 26 may be different, and I find that my app may not be able to ensure that all versions of Xcode 26 are successfully compiled. For example, my app can run on Xcode26.3 but will report an error at 26.4 (I have fixed it now). So I want to confirm which version of Xcode the jury uses to run my app, whether it is a known version or the latest version in the future. Thanks!
1
0
157
Feb ’26
Foundation Models support in Swift Playgrounds | SSC26
Hello. I'm building my Swift Student Challenge Project. But I noticed that the FoundationModels Framework isn't supported in Swift Playgrounds. My app uses ARKit, so it definitely should be tested on real device. So, is it possible to somehow implement a foundation models to my Swift Playgrounds app? Or is it possible to ask judges to test the app on real device launching it from xcode. Your answer is really important for because the functionality of my app directly depends on Foundation Models availability. Thank you!
1
0
165
Feb ’26
Foundation Models support in Swift Playgrounds | SSC26
Hello. I'm building my Swift Student Challenge Project. But I noticed that the FoundationModels Framework isn't supported in Swift Playgrounds. My app uses ARKit, so it definitely should be tested on real device. So, is it possible to somehow implement a foundation models to my Swift Playgrounds app? Or is it possible to ask judges to test the app on real device launching it from xcode. Your answer is really important for because the functionality of my app directly depends on Foundation Models availability. Thank you!
1
0
222
Feb ’26
Does an app relying on CoreLocation (GPS) fit the Swift Student Challenge judging criteria?
Hi everyone, I’m currently developing my submission for the Swift Student Challenge. My app idea heavily relies on CLLocationManager to track the user's movement (recording coordinates, altitude, and calculating distances) to provide a localized, real-world experience. I have a few questions regarding how this will be evaluated during the judging process: Testing Environment: Since the rules mention that Xcode app playgrounds are run in the Simulator, but submissions optimized for iPad are run on real devices, will the judges physically test an app that requires real-world walking/movement? Location Permissions: Will the judges accept the iOS location permission prompts to experience the app, or should I build a "Simulation Mode" with mock GPS data to ensure they can evaluate the core logic without leaving their desk? Judging Criteria: Does a location-dependent app fit well within the "Technical Accomplishment" and "Creativity" criteria, or is it too risky if the judges cannot test the physical movement aspect easily?
1
0
153
Feb ’26
Can I Upload a Single Screenshot Showing iPhone, iPad, and Mac Designs Together?
Hi everyone, I have a question about showcasing my Swift Student Challenge submission. My app includes layouts optimized for iPhone, iPad, and Mac, and I’d like to highlight that it works well across all three device sizes. Would it be acceptable to upload one combined screenshot that shows the same screen displayed on iPhone, iPad, and Mac side-by-side, to demonstrate the responsive design? Thanks in advance for any advice!
1
0
295
Feb ’26
Questions about content usage & submission file
Hi everyone, I have two questions that I hope someone from the community (or Apple team) could help clarify: Use of real Apple Executives in a creative scene In a short introductory scene of my app playground, I included the names and emojis representing Apple executives in a respectful and creative way. There are: No official logos No copyrighted assets No branding elements It is purely fictional and made for storytelling purposes. Would this be acceptable under the submission guidelines, or should all characters be entirely unrelated to real individuals? Submission file concern After submitting my application, I realized I may have accidentally uploaded the wrong ZIP file (I mean I'm not sure tbh). Is there any way to review the exact file that was submitted? Would it be possible to withdraw and resubmit again? If so, would that count as multiple submissions (since only one submission is allowed)? I’d really appreciate any clarification from those who may have experienced something similar or from the Apple team. Many thanks!
0
0
158
Feb ’26
protocol witness error in Playgrounds
I'm importing SwiftUI, Foundation and Charts into an iOS app I'm writing in Swift in Xcode Playgrounds and am getting this error: error: Couldn't look up symbols: protocol witness table for Foundation.Date : Charts.Plottable in Charts the code looks like this in just two example files: file 1, the view import Foundation import SwiftUI import Charts import PlaygroundSupport struct FirstChart_WithDates: View { private let data = ChartDateAndDoubleModel.mockData(months: 3) var body: some View { Chart(data) { item in BarMark( x: .value("Label", item.date, unit: .month), y: .value("Value", item.value) ) } .padding() .aspectRatio(1, contentMode: .fit) .dynamicTypeSize(.accessibility1) ChartDateAndDoubleModelView(data: data) } } struct ChartDateAndDoubleModelView: View { var data: [ChartDateAndDoubleModel] var body: some View { VStack { HeaderRowView(texts: ["date", "value"]) ForEach(data) { datum in HStack { Text(datum.date.formatted(date: .abbreviated, time: .omitted)) .frame(maxWidth: .infinity) // TODO: Format for 2 decimal places. Text(datum.value, format: .number.precision(.fractionLength(2))) .frame(maxWidth: .infinity) } } } .padding(.bottom, 8) .overlay(.quaternary, in: .rect(cornerRadius: 8).stroke()) .padding() } } struct HeaderRowView: View { var texts: [String] var body: some View { HStack(spacing: 2.0) { ForEach(texts, id: \.self) { text in Text(text) .padding(4) .frame(maxWidth: .infinity) .background(.quaternary) } } .font(.headline) .mask(UnevenRoundedRectangle(topLeadingRadius: 8, topTrailingRadius: 8)) } } and file 2, the model: import Foundation import SwiftUI import Charts // ChartDateAndDoubleModel.swift // // // Created by Michael Isbell on 2/10/26. // public struct ChartDateAndDoubleModel: Identifiable { public let id = UUID() public let date: Date public let value: Double } public extension ChartDateAndDoubleModel { static func mockData(months: Int = 5) -> [ChartDateAndDoubleModel] { var data: [ChartDateAndDoubleModel] = [] let calendar = Calendar(identifier: .gregorian) let currentDate = Date() for month in 0..<months { //add month to current date and append to data data.append( ChartDateAndDoubleModel( date: calendar.date(byAdding: .month, value: month, to: currentDate)!, value: Double.random(in: 0...1000) ) ) } return data } }
1
0
94
Feb ’26
Updating Apps on the AppStore no longer working for me.
I have been using Swift Playground to build and submit my apps to the appstore for around three years now. Recently I uploaded two of my apps but now when I submit them for approval an error is issued… “Unable to Add for Review”… (see pic attached). I don’t understand it because Playground does not use Xcode as far as I am aware? Can someone advise me what I can do to resolve this? Is it something I have to wait to be fixed by an Apple update?
Replies
1
Boosts
0
Views
68
Activity
2d
Swift Playgrounds and App Store Connect
Hello everyone, On my iPad when I press upload to App Store Connect, It tells me uploaded successfully to App Store Connect. When I go to App Store Connect and to Build section, My app is not there. Am I looking in the right place?
Replies
1
Boosts
0
Views
919
Activity
2d
Swift Playground issue with "getting started with apps"
There seems to be an error with a code checkpoint in Swift Playground "getting started with apps" It says to put a VStack inside an HStack and shows how to do it. my screen looks the same but it is not getting marked as correct which is preventing me from moving on. Any Ideas?
Replies
4
Boosts
1
Views
356
Activity
1w
How works Experiment (Documentation) in Swift Playground?
Experiment Create a constant with an explicit type of Float and a value of 4. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour
Replies
3
Boosts
0
Views
1.1k
Activity
1w
On iPad with Swift Playgrounds: How to open chapter as a playground?
Note On a Mac with Xcode installed, or on an iPad with Swift Playgrounds, you can open this chapter as a playground. Playgrounds allow you to edit the code listings and see the results immediately. (Note in page 3) (I would like to open the chapter or book: Swift Programming Language in Swift Playground on iPad) https://books.apple.com/ve/book/the-swift-programming-language-swift-5-7-beta/id1002622538?l=en-GB Best regards
Replies
1
Boosts
0
Views
706
Activity
1w
Swift Playgrounds Incompatibility with Xcode 16 Files and Swift Versions
I'm facing an issue with Swift Playgrounds and files created in Xcode 16. It seems that Swift Playgrounds does not support Swift 6, but even when I create files specifically with Swift 5, Swift Playgrounds still reports that the files are unsupported. This creates a significant problem because macOS Sequoia does not allow me to revert to Xcode 15, which might have offered better compatibility. As it stands, I can't find a solution to work seamlessly between Xcode and Swift Playgrounds. Has anyone else encountered this issue? Are there any workarounds or updates planned to address this compatibility gap? Any advice would be greatly appreciated!
Replies
6
Boosts
2
Views
1.2k
Activity
2w
Reoccurring data access prompt issue with Swift Playgrounds 4.6.4 on macOS 26.1
Hello, I am having a recurring issue using Swift Playgrounds version 4.6.4 on macOS 26.1. Upon opening a file and every other time I start typing in the code section I get a prompt, the image below, two or three times. It doesn't matter if I accept or decline all or some of the prompts, as soon as I start typing on another line I get prompted another two or three times for permission. It appears to me that prompt generates every time the preview pane tries to update. Declining the prompt breaks the preview but accepting the prompt only gets you through a single line of code before it appears again. I believe this issue started after I updated to macOS26.1 as I had not encountered it before. I've also opened other files with Swift Playgrounds and encounter the same problem. It could also be unrelated to the update and could be an issue with some permission setting somewhere, however, I have been unable to find what or where it could be. Is anyone else experiencing this? Thank you for your time :)
Replies
28
Boosts
19
Views
2.7k
Activity
2w
Using .mp3 files in Swift Playgrounds project
Hello, I have an issue with importing some .mp3 files into a swift playground project (in Xcode, not in the Playground app). They worked fine in the Xcode project, but for some reason playgrounds isn't able to find them. I imported them the exact same way as I did in the Xcode project.
Replies
4
Boosts
0
Views
1.4k
Activity
Feb ’26
Can I withdraw my submission and resubmit an updated playground?
Hello everyone, I have already submitted my app playground for the Swift Student Challenge. After submission I noticed a few things I would like to improve and fix. Is it possible to withdraw my current submission and then immediately resubmit an updated version? Any clarification (especially from Apple staff or anyone who has done this before) would be very helpful. Thank you!
Replies
1
Boosts
0
Views
273
Activity
Feb ’26
“Keep Going with Apps” Tutorial section will not complete.
Hello All, I am currently working through ”Keep going with Apps” in Swift Playground. The section in the tutorial “Add a DancingCreature view” will not complete. I have tried to type it is as written in the tutorial and even used the copy and paste button provided. I have restarted the app and my IPad with no success. I have attached a screen shot of the tutorial prompt. Here is the code block: import SwiftUI import Guide struct DancingCreatures: View { //#-learning-code-snippet(varDeclaration) @EnvironmentObject var data : CreatureZoo var body: some View { SPCAssessableGroup(view: self) { VStack { ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ } } ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ //#-learning-code-snippet(exp1) //#-learning-code-snippet(animationSolution) //#-learning-code-snippet(exp3) } } /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ } } } } struct DancingCreatures_Previews: PreviewProvider { static var previews: some View { DancingCreatures().environmentObject(CreatureZoo()) } } Device information: IPad Pro (11 inch, 2nd gen) iPad OS Version: 26.0.1 Playground Version: 4.6.4 Anyone else come across this? Thank you in advance.
Replies
7
Boosts
6
Views
724
Activity
Feb ’26
Are Xcode warnings like this safe to submit (won’t disqualify)?
I’m building a Swift Playgrounds app (.swiftpm) in Xcode 26.2 and I consistently see this warning, even on brand-new Swift Playgrounds apps created from the default template: “Skipping duplicate build file in Compile Sources build phase: /Users/.../.swiftpm/Media.xcassets” Everything builds and runs normally and all images/assets appear correctly, so it seems like it’s just an annoying warning. I’ve checked for duplicates and don’t see the asset catalog listed twice, but the warning still appears whenever I add an asset catalog to any playground project in Xcode. Is this warning safe to ignore for submission, and it won’t affect Swift Student Challenge eligibility?
Replies
5
Boosts
0
Views
340
Activity
Feb ’26
Xcode Playground and FoundationModels
I am trying to test FoundationModels in a Swift Playground in Xcode 26.2, macOS 26.3, and am running into an issue. The following simple code generates an error: import FoundationModels @Generable struct Specifications { @Guide(description: "Search for color") var color: String } I see the following error message in the console: error: AIPlayground.playground:4:8: external macro implementation type 'FoundationModelsMacros.GenerableMacro' could not be found for macro 'Generable(description:)'; plugin for module 'FoundationModelsMacros' not found The Xcode editor does not appear to recognize the @Generable or @Guide macros, despite importing FoundationModels. What step/setting am I missing?
Replies
2
Boosts
0
Views
152
Activity
Feb ’26
What Xcode version will be used for SSC evaluation?
Hello! Because the compilers used by different versions of Xcode 26 may be different, and I find that my app may not be able to ensure that all versions of Xcode 26 are successfully compiled. For example, my app can run on Xcode26.3 but will report an error at 26.4 (I have fixed it now). So I want to confirm which version of Xcode the jury uses to run my app, whether it is a known version or the latest version in the future. Thanks!
Replies
1
Boosts
0
Views
157
Activity
Feb ’26
Foundation Models compatibility with Swift Playground
There is a week left for end of the Swift Student Challange submissions. I've built an app which uses FoundationModels but unfortunately there is no support for it in the Swift Playground. Is there any chance it might be coming up in the following days?
Replies
1
Boosts
0
Views
167
Activity
Feb ’26
Foundation Models support in Swift Playgrounds | SSC26
Hello. I'm building my Swift Student Challenge Project. But I noticed that the FoundationModels Framework isn't supported in Swift Playgrounds. My app uses ARKit, so it definitely should be tested on real device. So, is it possible to somehow implement a foundation models to my Swift Playgrounds app? Or is it possible to ask judges to test the app on real device launching it from xcode. Your answer is really important for because the functionality of my app directly depends on Foundation Models availability. Thank you!
Replies
1
Boosts
0
Views
165
Activity
Feb ’26
Foundation Models support in Swift Playgrounds | SSC26
Hello. I'm building my Swift Student Challenge Project. But I noticed that the FoundationModels Framework isn't supported in Swift Playgrounds. My app uses ARKit, so it definitely should be tested on real device. So, is it possible to somehow implement a foundation models to my Swift Playgrounds app? Or is it possible to ask judges to test the app on real device launching it from xcode. Your answer is really important for because the functionality of my app directly depends on Foundation Models availability. Thank you!
Replies
1
Boosts
0
Views
222
Activity
Feb ’26
Does an app relying on CoreLocation (GPS) fit the Swift Student Challenge judging criteria?
Hi everyone, I’m currently developing my submission for the Swift Student Challenge. My app idea heavily relies on CLLocationManager to track the user's movement (recording coordinates, altitude, and calculating distances) to provide a localized, real-world experience. I have a few questions regarding how this will be evaluated during the judging process: Testing Environment: Since the rules mention that Xcode app playgrounds are run in the Simulator, but submissions optimized for iPad are run on real devices, will the judges physically test an app that requires real-world walking/movement? Location Permissions: Will the judges accept the iOS location permission prompts to experience the app, or should I build a "Simulation Mode" with mock GPS data to ensure they can evaluate the core logic without leaving their desk? Judging Criteria: Does a location-dependent app fit well within the "Technical Accomplishment" and "Creativity" criteria, or is it too risky if the judges cannot test the physical movement aspect easily?
Replies
1
Boosts
0
Views
153
Activity
Feb ’26
Can I Upload a Single Screenshot Showing iPhone, iPad, and Mac Designs Together?
Hi everyone, I have a question about showcasing my Swift Student Challenge submission. My app includes layouts optimized for iPhone, iPad, and Mac, and I’d like to highlight that it works well across all three device sizes. Would it be acceptable to upload one combined screenshot that shows the same screen displayed on iPhone, iPad, and Mac side-by-side, to demonstrate the responsive design? Thanks in advance for any advice!
Replies
1
Boosts
0
Views
295
Activity
Feb ’26
Questions about content usage & submission file
Hi everyone, I have two questions that I hope someone from the community (or Apple team) could help clarify: Use of real Apple Executives in a creative scene In a short introductory scene of my app playground, I included the names and emojis representing Apple executives in a respectful and creative way. There are: No official logos No copyrighted assets No branding elements It is purely fictional and made for storytelling purposes. Would this be acceptable under the submission guidelines, or should all characters be entirely unrelated to real individuals? Submission file concern After submitting my application, I realized I may have accidentally uploaded the wrong ZIP file (I mean I'm not sure tbh). Is there any way to review the exact file that was submitted? Would it be possible to withdraw and resubmit again? If so, would that count as multiple submissions (since only one submission is allowed)? I’d really appreciate any clarification from those who may have experienced something similar or from the Apple team. Many thanks!
Replies
0
Boosts
0
Views
158
Activity
Feb ’26
protocol witness error in Playgrounds
I'm importing SwiftUI, Foundation and Charts into an iOS app I'm writing in Swift in Xcode Playgrounds and am getting this error: error: Couldn't look up symbols: protocol witness table for Foundation.Date : Charts.Plottable in Charts the code looks like this in just two example files: file 1, the view import Foundation import SwiftUI import Charts import PlaygroundSupport struct FirstChart_WithDates: View { private let data = ChartDateAndDoubleModel.mockData(months: 3) var body: some View { Chart(data) { item in BarMark( x: .value("Label", item.date, unit: .month), y: .value("Value", item.value) ) } .padding() .aspectRatio(1, contentMode: .fit) .dynamicTypeSize(.accessibility1) ChartDateAndDoubleModelView(data: data) } } struct ChartDateAndDoubleModelView: View { var data: [ChartDateAndDoubleModel] var body: some View { VStack { HeaderRowView(texts: ["date", "value"]) ForEach(data) { datum in HStack { Text(datum.date.formatted(date: .abbreviated, time: .omitted)) .frame(maxWidth: .infinity) // TODO: Format for 2 decimal places. Text(datum.value, format: .number.precision(.fractionLength(2))) .frame(maxWidth: .infinity) } } } .padding(.bottom, 8) .overlay(.quaternary, in: .rect(cornerRadius: 8).stroke()) .padding() } } struct HeaderRowView: View { var texts: [String] var body: some View { HStack(spacing: 2.0) { ForEach(texts, id: \.self) { text in Text(text) .padding(4) .frame(maxWidth: .infinity) .background(.quaternary) } } .font(.headline) .mask(UnevenRoundedRectangle(topLeadingRadius: 8, topTrailingRadius: 8)) } } and file 2, the model: import Foundation import SwiftUI import Charts // ChartDateAndDoubleModel.swift // // // Created by Michael Isbell on 2/10/26. // public struct ChartDateAndDoubleModel: Identifiable { public let id = UUID() public let date: Date public let value: Double } public extension ChartDateAndDoubleModel { static func mockData(months: Int = 5) -> [ChartDateAndDoubleModel] { var data: [ChartDateAndDoubleModel] = [] let calendar = Calendar(identifier: .gregorian) let currentDate = Date() for month in 0..<months { //add month to current date and append to data data.append( ChartDateAndDoubleModel( date: calendar.date(byAdding: .month, value: month, to: currentDate)!, value: Double.random(in: 0...1000) ) ) } return data } }
Replies
1
Boosts
0
Views
94
Activity
Feb ’26