Swift Student Challenge

RSS for tag

Ask questions and connect with other challenge applicants.

Posts under Swift Student Challenge tag

103 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

SwiftData Relationship Delete Not Working (SwiftData/PersistentModel.swift:359)
SwiftData delete isn't working, when I attempt to delete a model, my app crashes and I get the following error: SwiftData/PersistentModel.swift:359: Fatal error: Cannot remove My_App.Model2 from relationship Relationship - name: model2, options: [], valueType: Model2, destination: Model2, inverseName: models3, inverseKeypath: Optional(\Model2.models3) on My_App.Model3 because an appropriate default value is not configured. I get that it's saying I don't have a default value, but why do I need one? Isn't @Relationship .cascade automatically deleting the associated models? And onto of that, why is the error occurring within the do block, shouldn't it be caught by the catch, and printed? I have put together a sample project below. import SwiftUI import SwiftData @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .modelContainer(for: Model3.self) } } } @Model class Model1 { var name: String @Relationship(deleteRule: .cascade, inverse: \Model2.model1) var models2: [Model2] = [] init(name: String) { self.name = name } } @Model class Model2 { var name: String var model1: Model1 @Relationship(deleteRule: .cascade, inverse: \Model3.model2) var models3: [Model3] = [] init(name: String, model1: Model1) { self.name = name self.model1 = model1 } } @Model class Model3 { var name: String var model2: Model2 init(name: String, model2: Model2) { self.name = name self.model2 = model2 } } struct ContentView: View { @Query var models1: [Model1] @Environment(\.modelContext) var modelContext var body: some View { NavigationStack { List(models1) { model1 in Text(model1.name) .swipeActions { Button("Delete", systemImage: "trash", role: .destructive) { modelContext.delete(model1) do { try modelContext.save() //SwiftData/PersistentModel.swift:359: Fatal error: Cannot remove My_App.Model2 from relationship Relationship - name: model2, options: [], valueType: Model2, destination: Model2, inverseName: models3, inverseKeypath: Optional(\Model2.models3) on My_App.Model3 because an appropriate default value is not configured. } catch { print(error.localizedDescription) } } } } .toolbar { Button("Insert", systemImage: "plus") { modelContext.insert(Model3(name: "model3", model2: Model2(name: "model2", model1: Model1(name: "model1")))) } } } } }
0
0
36
5h
Can I change iOS version in package.swift to use SwiftData?
For the swift student challenge I was hoping to use swift data, I found that since it's a playground app, in package.swift the defaults is set to iOS 16 which means you can't use swift data. I changed it to iOS 17 and everything works but I want to know if that goes against the rules in anyway, changing th bios version in package.swift? This was the code I changed in package.swift. let package = Package( name: "ProStepper", platforms: [ .iOS("17.0") ],
3
1
231
1w
Determining if a block of data was signed on the Secure Enclave
Hello, I'm exploring the Secure Enclave APIs, and I'm wondering if it's possible to "cryptographically" determine if a block of data was signed on the Secure Enclave. When I sign a block of data using the Secure Enclave (which implies using a key pair automatically generated by the enclave) and distribute the public key to others, is there any way to verify if the message was encrypted on it / its private key was generated by it? In other words, what I'm trying to achieve is to make sure that the public key hasn't been tampered with until it reaches its destination (including on-device threats, since otherwise I could've used a normal keychain item, perhaps?). For the purpose of this example, I'm not necessarily interested in figuring out if the key was signed on a certain device's enclave, but rather on any Secure Enclave. So, using something derived from the enclave's GID Key (described in the Apple Platform Security guide) would work for this.
2
0
200
1w
Unable to register for Swift Student Challenge Meet with Apple Session
Pretty much what the title says, I received the email from Apple today regarding the three sessions that are being conducted for participants. When I open the link, I'm shown the button to register, but when I click register, I'm asked to log in, following which I'm redirected back to the same page except the register button is now missing. I'm unsure if it has registered me, and I haven't received any email confirming the same.
3
1
212
6d
App Playground new Target
Hi everyone, Iā€™m working on my submission for the Swift Student Challenge and need some advice. I already have an existing app thatā€™s live on the App Store, and Iā€™d like to use the same app for my submission. However, while creating the App Playground, I noticed that Iā€™m unable to create additional targets. This is problematic because my app relies heavily on specific targets like ShieldAction, ShieldConfiguration, and DeviceActivityMonitor. Without these targets, the appā€™s core functionality wonā€™t work as intended. Is there a known limitation or workaround for this? How can I submit my appā€™s functionality within the constraints of the App Playground? Thanks in advance for your help!
2
0
193
2w
How to Add .mlmodel File to Xcode App Playgrounds (.swiftpm) Project?
Iā€™m working on an Xcode App Playground project (.swiftpm) and trying to add a .mlmodel file (e.g., Exercises.mlmodel) to it. However, when I add the .mlmodel file to my project, I encounter the following error: Exercises.mlmodel: No predominant language detected. Set COREML_CODEGEN_LANGUAGE to preferred language. The .mlmodel file works perfectly fine when used in a regular Xcode project (.xcodeproj), but this issue occurs as soon as I add the file in an App Playground project (.swiftpm). Steps Iā€™ve Tried: Ensuring the .mlmodel file is correctly added to the project folder. Checking the generated Core ML Swift code in a .xcodeproj environmentā€”works as expected. Searching for a way to explicitly set COREML_CODEGEN_LANGUAGE in a .swiftpm project, but it seems that Xcode does not provide this option. Any advice or solutions would be greatly appreciated! I have tried the solutions in these articles, however none of them worked: https://medium.com/@sofiadinizms/how-to-use-coreml-in-swift-playgrounds-8d5f001c5d15 https://developer.apple.com/forums/thread/743942?answerId=776359022#776359022
1
0
152
2w
Using Core ML in a .swiftpm file
Hi everyone, I've been struggling for a few weeks to integrate my Core ML Image Classifier model into my .swiftpm project, and Iā€™m hoping someone can help. Hereā€™s what Iā€™ve done so far: I converted my .mlmodel file to .mlmodelc manually via the terminal. In my Package.swift file, I tried both "copy" and "process" options for the resource. The issues Iā€™m facing: When using "process", Xcode gives me the error: "multiple resources named 'coremldata.bin' in target 'AppModule'." When using "copy", the app runs, but the model doesnā€™t work, and the terminal shows: "A valid manifest does not exist at path: .../Manifest.json." I even tried creating a Manifest.json manually to test, but this led to more errors, such as: "File format version must be in the form of major.minor.patch." "Failed to look up root model." To check if the problem was specific to my model, I tested other Core ML models in the same setup, but none of them worked either. I feel stuck and unsure of how to resolve these issues. Any guidance or suggestions would be greatly appreciated. Thanks in advance! :)
2
1
424
2w
Why am I unable to render .dae file in Playground?
This is my code in ContentView: import SwiftUI import SceneKit import PlaygroundSupport struct ContentView: View { var body: some View { VStack { Text("SceneKit with SwiftUI") .font(.headline) .padding() SceneView( scene: loadScene(), options: [.autoenablesDefaultLighting, .allowsCameraControl] ) .frame(width: 400, height: 400) .border(Color.gray, width: 1) } } } func loadScene() -> SCNScene? { if let fileURL = Bundle.main.url(forResource: "a", withExtension: "dae") { do { let scene = try SCNScene(url: fileURL, options: [ SCNSceneSource.LoadingOption.checkConsistency: true ]) print("Scene loaded successfully.") return scene } catch { print("Error loading scene: \(error.localizedDescription)") } } else { print("Error: Unable to locate a.dae in Resources.") } return nil } a.dae file exists in the Resources section of macOS Playground app. And a.dae can be viewed in Xcode. Console shows: Error loading scene: The operation couldnā€™t be completed. (Foundation._GenericObjCError error 0.) Any input is appreciated.
1
0
220
Dec ā€™24
Hi, I have an issue with app preview
I can't seem to access preview for any of my views in any of my swift projects at all (using Mac to code and using iPhone 16 pro as preview and simulation, simulation can work), even after restarting Mac and Xcode itself. The preview section has a popup saying "Cannot preview in this file, unexpected error occured" (for every file), please tell me what is wrong and help me solve it to see the preview, thank you! details
1
0
338
Nov ā€™24