As predictive code completion is natively included in Xcode, are we allowed to use it for the Swift Student Challenge?
Post
Replies
Boosts
Views
Activity
Using this adapted code snippet from the Apple Developer Documentation,
struct ContentView: View {
@State var nameComponents = PersonNameComponents()
var body: some View {
Form {
TextField(
"Proper name",
value: $nameComponents,
format: .name(style: .medium)
)
.onSubmit {
}
.disableAutocorrection(true)
.border(.secondary)
Text(nameComponents.debugDescription)
}
}
}
It runs and works as expected on my iOS device. When I use this same code in my macOS app, it has unexpected results. The validation mechanism (likely caused by format: .name(style: .medium) in order to bind the TextField to a PersonNameComponents instance, will not let me add spaces or delete all the text in the TextField. I have to write the first name in this format: "FirstLast" and then add a space in between the t and L. Are there any ways I can fix this on macOS while still binding my TextField to a PersonNameComponents instance?
When I create a new iOS playground in Xcode 16.0 with an iOS 18.0 SDK installed, I cannot use some of the new features such as the new way for programming tab layouts. When I just use an Xcode project, these features work as expected. In a playground, I get errors saying "x is only available in iOS 18.0 and later". I have noticed this for more than just this feature. Is there some way I can force the playground to run with iOS 18 as I have the appropriate SDKs installed?
Hello,
Although the Swift Student Challenge for 2025 has not yet been announced and is not officially taking place, I have a question regarding last year’s rules in the Swift Student Challenge. This is, of course, assuming the rules will be similar if the challenge runs again next year.
I am interested in utilizing CreateML to design a text classifier model. Given the substantial amount of data required for machine learning, am I allowed to outsource data from open-source libraries and/or social media platforms, provided that these resources abide by their terms of service? My primary concern is if I must create my own data as that will be time-consuming and more biased.
Thank you,
Jesse
Hello,
I am currently editing an iOS app playground in Xcode 16.0 on macOS 15.1 beta 3. When I create a new file using the SwiftUI View template, I am not prompted to name the file and it just uses the default file name. Afterwards, I am not able to rename the file to a name that suits my project. Is there a workaround for this?
Thanks!
I am wanting to create a 3D video game in Xcode for macOS, iOS, iPadOS, tvOS, and visionOS. I have heard that there are a few different ways to go about this such as MetalKit or SceneKit. These libraries seem to have little examples and documentation so I am wondering:
Are they still be developed/supported?
Which platform should I make a game in?
Where are some resources to learn how to use these platforms?
Are there other better platforms that I am just not aware of?
Thanks!
I have written some code for an interactive canvas here and it all compiles and works correctly:
import SwiftUI
extension CGPoint: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(x)
hasher.combine(y)
}
}
struct Line {
var points = [CGPoint]()
var color: Color = .red
var lineWidth: Double = 10.0
}
struct CharacterCanvas: View {
@State private var currentLine = Line()
@State private var lines: [Line] = []
var body: some View {
Canvas(opaque: false, colorMode: .linear, rendersAsynchronously: false) { context, size in
for line in lines {
var path = Path()
path.addLines(line.points)
context.stroke(path, with: .color(line.color), lineWidth: line.lineWidth)
}
}
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged({ value in
let newPoint = value.location
currentLine.points.append(newPoint)
self.lines.append(currentLine)
}) .onEnded({ value in
self.currentLine = Line()
})
)
.frame(minWidth: UIScreen.main.bounds.size.width, minHeight: UIScreen.main.bounds.size.width)
.border(.red)
.padding()
Button("Clear") {
currentLine = Line()
lines = []
}
ScrollView {
Text("Screen Size: \(UIScreen.main.bounds.size.width)")
VStack {
if !lines.isEmpty {
ForEach(lines.last!.points, id: \.self) { point in
Text("\(point.x), \(point.y)")
}
}
}
}
}
}
#Preview {
CharacterCanvas()
}
I now want to find 10 equally spaced points for each Line struct based on their points array so I can feed that into a CoreML model to classify the line type. How would I go about finding these 10 equally spaced points? I might also need to generate additional points if there are less than 10 points in the points array.
Thanks,
Jesse
I am currently working on a project for the Swift Student Challenge. One part of the app is for visualizing goals with a chart created using Swift Charts. In the app, you log your progress for the goal and then it should show up in the chart. My issue is that the data is not showing after it has been logged. Here are some code snippets:
Code For Chart View
Chart {
let currentDate = Date.now
BarMark (
x: .value("Day", "Today"),
y: .value("Score", goalItem.getLogItemByDate(date: currentDate).score)
)
}
.frame(maxHeight: 225)
.padding()
GoalItem Data Object
public class GoalItem: Identifiable {
public var id: String
var name: String
var description: String
var logItems: [String: GoalLogItem]
init(name: String, description: String) {
self.id = UUID().uuidString
self.name = name
self.description = description
self.logItems = [:]
}
func log(date: Date, score: Double, notes: String) {
self.logItems[dateToDateString(date: date)] = GoalLogItem(date: date, score: score, notes: notes)
}
func getLogItemByDate(date: Date) -> GoalLogItem {
let logItem = self.logItems[dateToDateString(date: date)]
if logItem != nil {
return logItem!
} else {
return GoalLogItem(isPlaceholder: true)
}
}
}
After logging something using the GoalItem.log method, why does it not show up in the chart? Are the variables not updated? If so, how would I get the variables to update?
Thanks
I am on macOS 14.3 Release Candidate with Xcode 15.2 and iOS 17.2 simulators installed. If I attempt to use iOS 17 features such as the SwiftData framework, it throws an error despite running my project on an iOS 17 simulator with an error such as "'model context' is only available in iOS 17.0 or newer". I am in an iOS App Playground but I don't believe that this will change much (correct me if I'm wrong). How could I fix this issue so I can use these features in my application?
Thanks