-1

Is there a way for me to click a button in one playground scene and then transitions to another scene? Preferably using SwiftUI

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
EliasFiz
  • 35
  • 7

1 Answers1

0

Yes, the markup formatting of Swift Playgrounds does support that. The syntax for it is

//: [Next Topic](@next)

Then you need to enable rendered markup for your playground, which you can do using Editor > Show Rendered Markup.

This is an Xcode and Swift playgrounds feature, it has nothing to do with SwiftUI or Swift itself.

For more information, see the Markup Formatting Reference Apple documentation.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • Unfortunately, I get a few errors when running this. I looked through the documentation but I still received errors. Use of unresolved identifier 'Welcome', and also the error Expected expression in list of expressions – EliasFiz May 10 '20 at 17:18
  • @EliasFiz what errors? This is a special markup comment, which isn't passed to the compiler, so it shouldn't result in any errors in any case. Also, you are using Swift playgrounds in Xcode on a Mac and not on an iOS device, right? – Dávid Pásztor May 10 '20 at 17:20
  • The link just doesn't appear – EliasFiz May 10 '20 at 17:22
  • @EliasFiz did you actually add several pages to your playground? And did you enable rendered markup? – Dávid Pásztor May 10 '20 at 17:23
  • Just to inform I am using the iOS platform in my playground settings – EliasFiz May 10 '20 at 17:24
  • Yes I did enable rendered markup but nothing changes – EliasFiz May 10 '20 at 17:26
  • The code does get greyed out, I think its because of the who // inform which makes swift think it is a comment – EliasFiz May 10 '20 at 17:28
  • @EliasFiz that's fine that it is an iOS target playground. It must be a comment, that's correct, but you need to make sure there is no space between the `:` and the `//`, since that (`//: `) makes it a Markup comment. You didn't answer my question about the pages though: are you sure your playground has at least 2 pages? [This](https://www.dropbox.com/s/shogw10iplearqe/Screenshot%202020-05-10%2018.34.56.png?dl=0) is how you add a new playground page. – Dávid Pásztor May 10 '20 at 17:35
  • It works now because I didn't know I had to put it with no indentation. But I was wondering whether it is possible to add a button inside of the game and not the code? – EliasFiz May 10 '20 at 17:40
  • @EliasFiz no, that is not possible. The Swift code itself cannot interact with the Playground. – Dávid Pásztor May 10 '20 at 17:44
  • So if I want to play this on my ipad can I only use 1 page? – EliasFiz May 10 '20 at 17:45
  • I would like to add that I am using Swift Playground, not Swift Playground Book – EliasFiz May 10 '20 at 17:56
  • You cannot play Swift playgrounds on iOS devices. The iOS compatible playgrounds which can be run inside the iOS Playgrounds app work completely independently and differently from their Xcode counterparts. If you want to be able to run your code on an iPad, you should drop playgrounds and create an iOS app. – Dávid Pásztor May 10 '20 at 18:11