While demonstrating Swift Playground to my students, I noticed that, unlike Xcode, it doesn’t seem possible to predefine or insert custom code snippets. In Xcode, we can easily create and reuse our own code snippets to improve teaching and development efficiency, but I couldn’t find a similar feature in Swift Playground.
Is there currently a way to predefine or insert custom code snippets in Swift Playground? Are there any recommended workarounds, or plans to support this feature in the future? Any suggestions or insights would be greatly appreciated.
Is there currently a way to predefine or insert custom code snippets in Swift Playground?
Not really. I encourage you to file an enhancement request for that feature. Please post your bug number, just for the record.
On the Mac you could get around this with any number of third-party apps that support macro expansion. On iPad, you can make a little headway with text replacements, that is, Settings > General > Keyboard > Text Replacements. For example, I defined !re
as a shortcut for import RegexBuilder
and it actually worked. However, that has limits, and it’s a bit clunky overall.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"