Posts

Post marked as solved
1 Replies
158 Views
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!
Posted
by jcovin293.
Last updated
.
Post marked as solved
1 Replies
219 Views
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
Posted
by jcovin293.
Last updated
.
Post marked as solved
5 Replies
509 Views
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
Posted
by jcovin293.
Last updated
.
Post not yet marked as solved
1 Replies
381 Views
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
Posted
by jcovin293.
Last updated
.
Post not yet marked as solved
1 Replies
342 Views
Hello, I have been working on my submission for the Swift Student Challenge and have been searching for a solution for how to complete a trivial task related to dates and calendars in Swift. After searching, I found an answer on Stack Overflow that works perfectly for my project. Am I allowed to submit a playground that includes this code or do I need to rewrite or reinvent the code somehow? Thanks
Posted
by jcovin293.
Last updated
.
Post marked as solved
1 Replies
358 Views
The Swift challenge page mentions playgrounds in both Swift Playgrounds and Xcode. Do I have to use an app playground or can I instead use an app project in Xcode? I feel more comfortable working with an Xcode project. Is it possible to convert my project to a .swiftpm file later? Thanks
Posted
by jcovin293.
Last updated
.