Post

Replies

Boosts

Views

Activity

Reply to Create ML Swift Student Challenge
If you need to use images fetched from the internet, the terms say that all resources must be included within the Playground: "Your creation should not rely on a network connection and any resources used in your app playground should be included locally in the ZIP file. Submissions will be judged offline." You can store images locally, within your Playground, and "ship" them with your app. If you are asking if you may use photos from the internet to train ML models, that depends on the usage terms & license. When using photos from the internet, always check the license to see how these may be used and if any attribution is required.
Jan ’24
Reply to Swift Playgrounds version of 'Copy Bundle Resources' build phase
Hi! I am not entirely sure if Swift Packages (a Swift Playground is essentially a special type of Swift Package) support editing build phases like in Xcode projects. When adding the folder to your playground (either by drag & drop or the plus button in the bottom left), wasn't it automatically placed within a "Resources" folder? It believe the USDZ needs to be placed within the generated Resources folder, not at the root of your playground. Then, you can access it using Bundle.main.url (and perhaps also Bundle.main.path): // make sure that "filename" doesn't contain the extension! guard let url = Bundle.main.url(forResource: filename, withExtension:"usdz") else { fatalError("Couldn't find the USDZ file.") } If you really need multiple Resources folders, a "hacky" thing you could do is to edit the Package.swift file. Control-click the Playground file in Finder and choose theShow package contents option, then open the Package.swift file and edit the target's resources: targets: [ .executableTarget( name: "AppModule", path: ".", resources: [ .process("Resources"), .process("Second Folder") // your second folder ] ) ] But make sure to pay attention to the warning that you may have at the beginning of this file: // WARNING: // This file is automatically generated. // Do not edit it by hand because the contents will be replaced. This file's contents may change when you edit other settings such as the App Icon from within Xcode. From my testings the resources folders seem to stay intact, but it's good to keep the warning in mind. Thus, the best way would be to simply use the provided "Resources" folder.
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’24
Reply to How can I use a CreateML model in Swift Playgrounds
I believe this is a build issue in Xcode 15. For reference, I reported this as FB13521432. When I add an ML model (I tried .mlmodel, .mlpackage or .mlmodelc) to my App Playground's Resources folder in Xcode 15, the build fails with 1-2 errors, even if I don't use the models within the playground's code. The first error I get is related to multiple build files with the same name being produced. Here is what I get with an .mlmodel or .mlpackage file: error: Unexpected duplicate tasks note: Target 'playground' (project 'playground') has write command with output /Users/[user]/Library/Developer/Xcode/DerivedData/playground-dzqpmayqqzdqoqebzuczjghhqqbk/Build/Intermediates.noindex/playground.build/Debug-iphoneos/playground.build/e1be5a3b551803f068478ad1867f7edd.sb note: Target 'playground' (project 'playground') has write command with output /Users/[user]/Library/Developer/Xcode/DerivedData/playground-dzqpmayqqzdqoqebzuczjghhqqbk/Build/Intermediates.noindex/playground.build/Debug-iphoneos/playground.build/e1be5a3b551803f068478ad1867f7edd.sb A similar error is produced when using compiled models (.mlmodelc): Multiple commands produce '/Users/[user]/Library/Developer/Xcode/DerivedData/playground-dzqpmayqqzdqoqebzuczjghhqqbk/Build/Products/Debug-iphoneos/playground.app/coremldata.bin' The second error I get when using ML models that weren't compiled is related to COREML_CODEGEN_LANGUAGE: No predominant language detected. Set COREML_CODEGEN_LANGUAGE to preferred language. Did you also get these build issues?
Jan ’24
Reply to Swift Student Challenge
I don't think there's a direct conversion method available, but you can copy the Swift files directly to the playground. For example, provided that you use SwiftUI, you can directly drag and drop the App, ContentView and other View files into your playground, and everything should work fine. But you will also need to copy the assets and resources separately and may require additional work. An example is when you use CoreML models (I need to look into this further, perhaps watch this thread for updates if you use ML models). Unfortunately, I am not entirely sure what run destination will be chosen in Xcode. I also asked this last year in this thread, and you might be able to include some specific instructions with your submission. But I would definitely recommend you to take on a challenge and make your app available on iPad / Mac, especially if you use SwiftUI, since it makes things easier. By the way, the Mac and iPad app should look pretty similar since the Mac options use Catalyst. Also, since you said you already made an app, you might need to make sure your playground will not use external resources (i.e. the internet), since that was in last years' terms.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24
Reply to FB13516799: Training Tabular Regression ML Models on large datasets in Xcode 15 continuously "Processing"
I've tried to look into this further with the Console app, and it seems that everything might be working but very slowly due to the large dataset. However, I don't remember this process being that slow on Xcode 14. The only reports I found were some cpu usage and wakeups diagnostic reports. After leaving it process the data for a while, I eventually got some <private> class has successfully loaded the model at <private>. and The optimizer converged after ... iterations. streamed by the MLRecipeExecutionService (CoreML) and IntelligencePlatformComputeService (CoreML) processes after 5 minutes. But after 30 minutes the training is still not finished. Another log message I found is the following: <private> class was unable to load the model at <private> with error: <private>; The model loader is going to use another class.
Topic: Machine Learning & AI SubTopic: General Tags:
Jan ’24
Reply to Swift Student Challenge
When you created your apps in Xcode, you probably made an Xcode project (with the .xcodeproj extension). The challenge requires you to make a Swift Playground that you can make with either Xcode or Swift Playgrounds. To make a Swift Playground, check the instructions in this thread. Regarding your age, the full terms and conditions of the 2024 challenge are not yet available, but they will be released in February according to the website. Last year, it was specified in the terms that your parents / legal guardians may send an email to swiftstudentchallenge@apple.com to request permission if your age is under the minimum one in your region. If you would like to check the terms, it was specified in the paragraph before submission requirements. Here's a thread from last year if it helps.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24
Reply to An error appears (Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value) when I try to add a scene file with the .sks extension to an app playground type project with the .swiftpm extension
Hi and happy new year! The error indicates that the file wasn't found - the app usually searches the file inside the Resources folder. I am not sure if moving it inside the Resources folder inside GamePlayground would work. If it doesn't, try adding the scene again so that a "global" Resources folder is created (either drag & drop the scene or click the plus button in the bottom left.
Topic: Media Technologies SubTopic: Streaming Tags:
Jan ’24
Reply to iOS 17 Features being depreciated
Hi! It seems that App Playgrounds require support for iOS 16.0 on this version of Xcode (not sure if this is a bug or intended for compatibility reasons). Even though you want to run your app on an iOS 17.0 device, the App Playground is set to build for iOS 16 devices too, and this is why your build fails (remember, to run a code it must first be built, and building requires your code to work on all devices it is configured for, not just on the one you use to test it). You should've received some relevant error messages and fixes that mention the if #available version check or the @available(iOS 17.0, *) attribute. These may be useful If you want to maintain the iOS 16 compatibility. This is analogous to changing the minimum iOS deployment version in an .xcodeproj. You could use the if #available version check like this: import SwiftUI struct ContentView: View { var body: some View { VStack { if #available(iOS 17.0, *) { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("iOS 17.0") } .defaultScrollAnchor(.bottom) } else { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("iOS 16.0") } } } } } Or you could add the @available(iOS 17.0, *) attribute to the enclosing View like this: import SwiftUI @available(iOS 17.0, *) struct ContentView: View { var body: some View { VStack { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") } .defaultScrollAnchor(.bottom) } } } And then, in the App struct, use the if #available version check: import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { if #available(iOS 17.0, *) { ContentView() } else { // Fallback on earlier versions Text("This feature requires iOS 17.0.") } } } } Now, if you want a "hacky" method, you could edit the package files of your App Playground. To do this, go to File > Show in Finder, and then open the Package.swift file. After that, you can change the .iOS("16.0") line to 17.0. Also, I recommend you to use the latest Xcode version & macOS (they bring bug fixes and security improvements 😁). Good luck and Happy New Year!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to Swift Student Challenge Playground More Than 3min Content
I recommend you check out this thread. I believe the 3-minute limit does not mean the judges should be able to look through the entire app within that time, but rather that they need to be able to get an idea of what it does in 3 minutes. For example, for a level-based game, if one / a few levels can be solved within the time limit, I think it should be fine (even though the app has multiple levels). What you'll have to do is make sure that the core parts of your app will be experienced within the allocated time. You can also think of it like this: can you explore all the content within the apps you use in three minutes? Not necessarily, but you can find out what the apps are about within that time. As you said, you could add a message after the first quiz that says something like "Congratulations! You finished this quiz. You can also solve other quizzes, do x, or y". I did something similar last year. I thought it would be a good idea since it indicated what else was left to do in my app. Perhaps you can achieve this in other ways too - for example, by indicating what your app does when it is first opened (using a similar message), or through a quick walk-through tutorial that is part of your app. Experiment and see what works best for you and your project. Good luck!
Nov ’23
Reply to Add resources in Swift Playgrounds 4
The Resources folder should be automatically created when you add a resource file such as a sound file, or a CoreML model, and you don't need to modify the Package.swift file. To add files to your Resources folder, you can drag and drop them or go to File > Add File, and select your resource. If your question is how to add another folder that works as a resource folder, you can add it in the resources part of Package.swift like this: targets: [ .executableTarget( name: "AppModule", path: ".", resources: [ .process("Resources"), /* don't forget the comma */ .process("OtherFolder") // the folder you want to add as a resources folder (replace OtherFolder with the desired name) ] ) ] If you're asking how to edit the Package.swift file, I'm not sure if you can open it in Playgrounds. On macOS, you can right click on the App Playground > Show In Finder to get to its location, and then right click > show contents on the app to see the its files, including the Package.swift file. To use your resource files, you need to use something like let url = Bundle.main.url(forResource: "ResourceFile", withExtension: "txt") in combination with something else, depending on what you want to use it for.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’23