Post

Replies

Boosts

Views

Activity

Circular Reference Error in Xcode 26
I have my project running perfectly fine on Xcode 16. However, in Xcode 26 it doesn't build due to an error that I do not understand. I have three files that pertain to this error: // FriendListResponse.swift import Foundation struct FriendListResponse: Decodable { var friendships: [Friendship] var collections: [FriendCollection] } // Friendship.swift import Foundation struct Friendship: Decodable { var createdAt: String var friendId: Int var friendUserId: Int // user ID of the friend var friendUsername: String var id: Int var tagNames: [String] } // FriendCollection.swift struct FriendCollection: Decodable { var id: Int var permalink: String var tagNames: [String] var title: String } On the first file, FriendListResponse.swift, I am the simple error message "circular reference." I do not understand how these self-contained structs could create a circular reference. Although I have other data types in my project, none of them are even referenced in these files except for Friendship and FriendCollection. The FriendListResponse is a struct that is created from JSON values that are fetched from an API. This is the function that fetches the JSON: public static func listFriends(username: String) async throws -> [Friendship] { let data = try await sendGETRequest( url: "people/\(username)/friends/list.json" ) print(String(data: data, encoding: .utf8)!) let decoder = JSONDecoder() decoder.keyDecodingStrategy = .convertFromSnakeCase let wrapper = try decoder.decode(FriendListResponse.self, from: data) return wrapper.friendships } // Note: the function sendGETRequest is just // a function that I have created that takes a set // of parameters and returns a data object // using the HTTP GET protocol. I don't think // that it is related to this issue. However, if you // think that it is, I can share the code for that. This error has also happened in a few other cases within contained networks of my data structure. I do not know why this error is only appearing once I launch Xcode 26 beta with my project files. I would think that this error also would appear in Xcode 16.4. Any help would be greatly appreciated in my process to compile my project on Xcode 26!
7
0
193
Jun ’25
Suggestions for OAuth2 in Swift
Hello! I have a few questions about integrating an OAuth2 API into my Swift application. I am using this API to access user data from the website (users will authenticate themselves within the app). I have seen other apps use this API in the way that I am describing it so I know that it is possible. However, I am not sure how to implement it. Are there any recommended ways to use an OAuth2 API in my application? The API that I am using does not specifically say that it supports PKCE. However, I have heard from some sources that it does. If it does not support PKCE, how do I still create a secure app infrastructure that will pass App Store Review? At a more basic level, what is the difference between OAuth2 and PKCE? What should I use in my app? Are there any resources to learn a little bit more about these protocols so that I understand them better? Thanks!
0
0
36
Jun ’25
PersonNameComponents TextField Not Responding As Expected on macOS
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?
0
0
297
Oct ’24
iOS 18 features not working in Xcode iOS playground
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?
0
2
539
Oct ’24
External Data Use for Swift Student Challenge
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
2
0
716
Oct ’24
What Platform to Use To Make a Game in Xcode?
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!
1
0
1.6k
May ’24
How do I get 10 equally spaced points along a CGLine in SwiftUI?
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
1
0
810
Apr ’24
Swift Charts Won't Update a Variable Value
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
5
0
1.6k
Feb ’24
iOS 17.0 features not working when I have an iOS 17 simulator installed
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
1
0
1.3k
Jan ’24
Can I Use Code From Stack Overflow?
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
1
0
481
Jan ’24