Post

Replies

Boosts

Views

Activity

Reply to Swift Student Challenge Vision
It seems that your code doesn't use any Vision Framework features, at least not yet. Removing the Vision import doesn't change anything to your current code. Perhaps you want to add some Vision-related features later? I tried to run your code, and I only had to make some small changes in your ImagePicker since PresentationMode was deprecated: struct ImagePicker: UIViewControllerRepresentable { @Environment(\.dismiss) private var dismiss @Binding var image: UIImage? func makeUIViewController(context: Context) -> UIImagePickerController { let picker = UIImagePickerController() picker.delegate = context.coordinator return picker } func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {} func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { var parent: ImagePicker init(_ parent: ImagePicker) { self.parent = parent } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { if let uiImage = info[.originalImage] as? UIImage { parent.image = uiImage } parent.dismiss() } } } Everything seemed to work as expected after that. I was able to pick an image and it was displayed in the ContentView. Also, if you want a SwiftUI Photo Picker implementation (i.e. doesn't rely on UIKit / UIViewControllerRepresentable), you can find out how to do it in this WWDC22 Session video and sample code. But your ImagePicker seems to work fine too.
Jan ’24
Reply to XCode Project for Student Project
I believe you are only allowed to submit App Playgrounds (.swiftpm) files as it is described on the eligibility page. That was the case for last year's challenge as well. Make sure you submit an App Playground, not an Xcode Playground. Here is a thread that explains how to properly choose the right thing in Xcode or Swift Playgrounds. Most likely you will be able to move your code into an App Playground with minor changes if you use SwiftUI, as I explained in this thread. It should be a mater of drag and dropping the View files. If you use resources such as ML models, these might require additional work.
Jan ’24
Reply to Swift Student Challenge Vision
I believe you are only allowed to submit App Playgrounds (.swiftpm) files as it is described on the eligibility page. That was the case for last year's challenge as well. Make sure you submit an App Playground, not an Xcode Playground. Here is a thread that explains how to properly choose the right thing in Xcode or Swift Playgrounds. I assume you're referring to the Vision Framework, not visionOS. I would try to find out why your app doesn't work as expected in Playgrounds, as I believe it may possible to use this framework as well, perhaps with a few small changes. What is the issue with your Vision code? Make sure to check the full terms and conditions on February 5th.
Jan ’24
Reply to How can I find info.plist in Xcode 15.2 playground
Hi! App Playgrounds don't really have an Info.plist, but you can add capabilities such as camera access via Xcode. Click on your project > Signing Capabilities, then click the "+ Capability" Button. Add the capabilities you want, such as camera access, via the menu that appears. Then, at the bottom of the Signing & Capabilities page, you should have the new capability added, where you can also modify settings such as the purpose string for camera access: Internally, Xcode adds these capabilities to a Package.swift file included with your project which replaces the Info.plist. This file is not directly accessible within Xcode (you can view it in Finder if you show the .swiftpm's contents), but you can add capabilities from Xcode as I explained above.
Jan ’24
Reply to Does the app will be revised on a iPad or a MacOS?
Last year, you had to pick from one of these options: Swift Playgrounds on iPad Swift Playgrounds on Mac Xcode on Mac I guess it will probably be similar this year, if not the same. While it didn't specify if Apple Silicon Macs will be used, I suppose that will be the case, though I believe your project may work fine on Intel-based ones too. I'm curious why your app doesn't work well on iPad, including M1 ones. Sounds like your app uses quite a lot of processing power, but I guess it should work on M1 iPads as well. Maybe you need to make some additional changes to fully support them. But, in any case, I think you will be able to select one of the options above. What I'm curious about is what run destination will be chosen in Xcode (iPhone / iPad Simulator, Mac Catalyst app etc.) - but since I made my app fully support all platforms last year, it did not really matter for me. If you have other any specific instructions to run your playground, last year I received this response, and it might also apply this year. Do not rely solely on this information and be sure to check the updated terms and conditions on February 5th! A link to the terms should appear here when the challenge opens.
Topic: App & System Services SubTopic: Hardware Tags:
Jan ’24
Reply to Using UIKit & Storyboards
I just tested this by creating a new iOS Xcode project with Swift & UIKit, then copied the Swift files to a new App Playground (and deleted the old MyApp and ContentView SwiftUI files). It seems to work fine (I'm not entirely sure about storyboards though), which was expected in my opinion - as long as you have the necessary code and the @main attribute somewhere in your code, the app should compile and run. What I'm not entirely sure of is how / if storyboards are supported in Playgrounds. However, I'd definitely recommend you to learn SwiftUI as well. It should be easy to learn using the available resources and you can also use UIKit with SwiftUI code. Good luck!
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’24
Reply to Xcode Playground
Hi, yes, you can modify the Package.swift file included in your playground. It is normally not accessible within Xcode / Swift Playgrounds but you can edit it if you show the playground's contents in Finder. This file's names comes from Swift packages (Playgrounds are essentially a special type of Swift Package). Be aware that this file is automatically generated, so there may be chances for it to be overwritten when you change playground's settings, as the warning at the top of it suggests (I would also like more insight into this if somebody else knows - is editing the minimum target version or the target resources a good practice, or is it at risk to be overwritten? From my testings, it seems to work fine with changing the target resources). Check this thread for ideas on how to support older iOS versions in your code, or modify your Package.swift file like I explained above. If this is for the Swift Student Challenge (as your tag suggests), I'm not sure if it's okay to modify the minimum target version. Perhaps the judges will have the latest version of iPadOS / macOS, but currently the website says the following: "Your app playground must be built with and run on Swift Playgrounds 4.4 or later (requires iPadOS 16 or macOS 13.5) or Xcode 15 on macOS 13.5 or later. You may incorporate the use of Apple Pencil." https://developer.apple.com/swift-student-challenge/eligibility/
Jan ’24
Reply to Completed cs50. Now I want to participate in swift student challenge but I'm so confused. Where do I even start?
Quinn's resources are great! If you don't mind, I would like to add a few other resources that you might find helpful as well: The resources already listed in the Get Ready section of the Swift Student Challenge website. The Swift Programming Language docs, especially the Swift tour part. Also, you can go deeper and read all the topics included in these docs, especially if you want to gain a deeper understanding of the language itself. The SwiftUI sample apps. This also appears on the Swift Student Challenge's website. After you are comfortable with Swift & SwiftUI, you can learn how use the many technologies (such as ML frameworks) described in the Apple Developer docs, watch WWDC videos about these, and explore other resources as well. But of course, the idea would be to simply just start with one of them and dive deeper into this subject. As you gain more knowledge, you will know what you'll need to focus on next. Also, there are two main apps that you can use for coding Swift apps for Apple platforms: Xcode and Swift Playgrounds. In both you can create App Playground projects (if you need guidance regarding this, check this thread), but the latter is beginner friendly and can run on iPad, while the former is more advanced.
Jan ’24
Reply to How can I use a CreateML model in Swift Playgrounds
I believe I finally found an overall solution that works for both compiled (.mlmodelc) and uncompiled models (.mlmodel, .mlpackage), plus an explanation of why .mlmodelc files may not be correctly copied in the bundle during the build process. I also sent a similar response in this recently opened similar thread. Steps to fix the bundling issues You will need to edit the Package.swift file manually. Go to the playground in Finder, control-click it and select Show Package Contents. Then, open the Package.swift file. At the bottom of this file, you'll find the following target section, which might look different for you: targets: [ .executableTarget( name: "AppModule", path: ".", resources: [ .process("Resources") // copy resources to the app bundle without keeping folder structure ] ) ] The .process("Resources") line indicates that the resources (in your case, your model) must be copied without keeping the original folder structure. Say you have 2 folders inside the Resources folder, and in each of these you have a few files. Only the files inside will be copied in the bundle, and the 2 original folders won't appear. You will need to replace (or add, if you don't have the process() function) process() with copy(), which maintains the internal folder structure (I explained below why). You can either use .copy("Resources"), which require you to change the model's bundle URL inside your code, not this Package.swift file to this: Bundle.main.url(forResource: "Resources/MobileNetV2", withExtension:"mlmodelc") Notice this includes "Resources/" inside the path. Or you might directly copy the model folder to the Bundle using .copy("Resources/MobileNetV2") and keep the URL without the "Resources/" part - note that this way, any other files in the Resources might not be available unless you add other process / copy functions to your Package.swift file. For more information about process() and copy(), check the docs for bundling resources with Swift Packages (since a Swift Playground is a special type of a Swift Package). Why compiled models are not correctly copied in the bundle using process() Compiled ML models are essentially a folder that contains one or more coremldata.bin files (and maybe other files as well) - in fact, they appear as a folder on the filesystem (you can cd into them in Terminal). The reason why these .mlmodelc aren't correctly copied to your bundle when using .process("Resources"), or may give a build error with certain models that contain more coremldata.bin files, is that the internal folder structure is not copied, but only the files inside it. That's why you found that your bundle contained a coremldata.bin file only. Using the previously mentioned .copy() method, you can keep the internal folder structure. How do I use my ML models, now that I can bundle them with my App? You can create your own code that reads the model from the bundle and compiles it if necessary, or you can copy the Model Class file that is usually generated in Xcode projects. You will need to make the necessary changes related to the file's Bundle URL. Why do uncompiled models result in build issues? Regarding why uncompiled models cannot be built in Xcode, something similar to the compiled models issue might be happening, but these do not appear as folders on the filesystem - so this should probably not happen and perhaps it is a build issue. It also seems that .mlmodels are not compiled at runtime, which I believe used to happen in the previous Swift Playgrounds / Xcode versions from last year. So, if the bundling issue is fixed and .mlmodels are bundled with your app, you might need to insert additional code that compiles the model with something like this: let compiledModelURL = try await MLModel.compileModel(at: url) let model = try MLModel(contentsOf: compiledModelURL) Let me know if this works!
Jan ’24
Reply to Swift Playground Bundle can't find Compiled CoreML Model (.mlmodelc)
I believe I finally found an overall solution that works for both compiled (.mlmodelc) and uncompiled models (.mlmodel, .mlpackage), plus an explanation of why .mlmodelc files may not be correctly copied in the bundle during the build process (even though it succeeds). I also sent a similar answer to this other thread, and included a few more details about an issue unique to Xcode and uncompiled models. You will need to edit the Package.swift file manually. Go to the playground in Finder, control-click it and select Show Package Contents. Then, open the Package.swift file. At the bottom of this file, you'll find the following target section, which might look different for you: targets: [ .executableTarget( name: "AppModule", path: ".", resources: [ .process("Resources") // copy resources to the app bundle without keeping folder structure ] ) ] The .process("Resources") line indicates that the resources (in your case, your model) must be copied without keeping the original folder structure. Say you have 2 folders inside the Resources folder, and in each of these you have a few files. Only the files inside will be copied in the bundle, and the 2 original folders won't appear. You will need to replace (or add, if you don't have the process() function) process() with copy(), which maintains the internal folder structure (I explained below why). You can either use .copy("Resources"), which require you to change the model's bundle URL like this: class var urlOfModelInThisBundle : URL { let bundle = Bundle(for: self) return bundle.url(forResource: "Resources/MobileNetV2", withExtension:"mlmodelc")! } Or you might directly copy the model folder to the Bundle using .copy("Resources/MobileNetV2") and keep the original URL - note that this way, any other files in the Resources might not be available unless you add other process / copy functions to your Package.swift file. For more information about process() and copy(), check the docs for bundling resources with Swift Packages (since a Swift Playground is a special type of a Swift Package). Why compiled models are not correctly copied in the bundle using process() Compiled ML models are essentially a folder that contains one or more coremldata.bin files (and maybe other files as well) - in fact, they appear as a folder on the filesystem (you can cd into them in Terminal). The reason why these .mlmodelc aren't correctly copied to your bundle when using .process("Resources"), or may give a build error with certain models that contain more coremldata.bin files, is that the internal folder structure is not copied, but only the files inside it. That's why you found that your bundle contained a coremldata.bin file only. Using the previously mentioned .copy() method, you can keep the internal folder structure. Regarding why uncompiled models cannot be built in Xcode, something similar might be happening, but these do not appear as folders on the filesystem - so this should probably not happen and perhaps it is a build issue. It also seems that .mlmodels are not compiled at runtime, which I believe used to happen in the previous Swift Playgrounds / Xcode versions from last year. Let me know if this works!
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24
Reply to How can I use a CreateML model in Swift Playgrounds
I think I found out why I couldn't build playgrounds with .mlmodelc files - it seems that the playground I used had a Resources folder but it didn't appear in the target's resources in Package.swift due to some reason - perhaps I manually played with it at some point and forgot about it. Editing this file / making a new playground solved the build issues for me. However, I still get the same build problems with uncompiled models (.mlmodel) in Xcode 15.
Jan ’24
Reply to Swift Playground Bundle can't find Compiled CoreML Model (.mlmodelc)
I'm curious, have you tried using the coremldata.bin file as a resource? It should contain the model data. I haven't tried this and it's just a guess. I'm still getting issues with tabular regressor ML models in Swift Playgrounds as well, just as in Xcode - that multiple commands produce coremldata.bin. I'll look into this further, perhaps with other models too (including MobileNetV2). Also, it seems that .mlmodel (uncompiled) files are simply copied to the bundle and not compiled - which I believed it used to happen last year, at least in Xcode 14. Perhaps CoreML models are completely unsupported in Swift Playgrounds?
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24
Reply to Swift Playground Bundle can't find Compiled CoreML Model (.mlmodelc)
I haven’t looked into this further than you did yet, but I think I also reproduced this same issue a few days ago when I was trying to find the differences between Xcode and Swift Playgrounds regarding building projects with ML models. What I know for sure is that at least the app builds successfully, compared to doing the same thing in Xcode - more details about this are available in this thread.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24