Swift Playgrounds on iPad: How to add source files properly?

I have been attempting to add an existing swift playground as a source file to another playground on the ipad for the sake of working with classes and subclasses. I am attempting to do all of this natively on my ipad pro.


I cannot get the main file to work properly with auxillary source files. For instance, when trying to declare a new variable of a class type (contained in file as an auxillary source) I end up getting the error 'use of unresolved identifier'.


Steps I have taken:


  • Declared class and all members are public
  • Added the class playground as a file in a new playground.
  • Select 'Use' for the class file in the add menu.

I managed to get source files working in a playground properly on my mac. I exported the working playground along with source files to my ipad. The source files will not work on the ipad, but they will on my mac. I am still having the issue of 'use of unresolved identifier' when attempting to create an instance of a class object.


What is it that I may doing improperly? Is this a bug maybe?

So I upgraded to the GM and downloaded Playgrounds via the app store yesterday and I cannot get this feature to work still. The code all looks correct and I was able to replicate it using the same source code file in a playground on the mac. I even created an playground with embedded source files then transferred it to my ipad. Works on the computer, but not the ipad.


Anyone able to test this out and see if there is anything I am doing wrong?

Have you figured out how to do this. I thought this would be something pretty easy to do, but I have had toruble figuring this out.

thanks,

Unfortunately I have not. I am wondering if it will only work when you publish content on the playgrounds app instead of simply linking files natively inside the app. I will say that it is a bit of a disappointment as this would help with small bits or productivity on the go when I don't have the laptop.

I’m experiencing the same issue. It’s sad that no one at Apple feels the need to give us more information about this issue.

So over the winter break I updated all my devices to the latest OS and now I can try this out (-: Reading through the above it seems that the goal is to create a playground where a mostly-hidden file provides helper code to the main playground. I tried that here and it’s working for me. Specifically:

  1. On an iPad running iOS 15.2, I ran the latest Swift Playgrounds app (4.0).

  2. At the main screen I tapped the plus (+) button above Playground in the More Playgrounds section at the bottom.

  3. In the playground I revealed the sidebar by tapping the toolbar button at the top left.

  4. I tapped Source Code > UserModule > SharedCode.swift.

  5. I replaced the content of that source file with:

    public let greeting = "Hello Cruel World!"
    
  6. I switched back to the Main tab.

  7. I added the code:

    print(greeting)
    
  8. I tapped the Run My Code button.

  9. The playground compiled and ran. A red dot appeared above the console button in the bottom right. I tapped that.

  10. I saw the expected greeting.

This seems pretty obvious so I’m clearly not testing this the way that you folks are testing it. Can someone take my instructions above, tweak them to reproduce the problem, and then post them here? I’ll then try that out and see if I can spot what’s wrong.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Swift Playgrounds on iPad: How to add source files properly?
 
 
Q