UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Xcode14 how to open two different playground files within the same window?

Forums > 100 Days of SwiftUI

Hi, I newly installed the latest Xcode 14.3.1, and am encountering a navigational problem.

There are two different playground files I want to have open. After I open the 1st file, a new Xcode window opens to show the file. When I hit cmd+o to open the 2nd file, a new 2nd window opens to show the 2nd file. But I don't want two different windows, I want just one window with two tabs. That seems impossible?

I have tried Google search, and different navigational settings, as well as menu options. Nothing seems to work. When I read the Xcode documentation, I can't quite find as a definitive simple answer as to whether I can, or can not, open two files in the same window.

What am I missing? Please help. Thank you.

2      

Seems a little odd as to why you would want to do this? Is there anything specific the playground does that an Xcode project can't do? Playground, well for me anyway seemed a little basic and maybe a little limited on what it can do. Well I say that, but I'm sure there are workarounds for preview and all that. Here's what you could do...Create a project in Xcode and add two swift files and name the files PlaygroundOne and PlaygroundTwo? And then add a button / nav link to switch between the two..... I added a file to my project a while back called MyPlayground. And so I don't have to switch out of my project.

2      

Thank you so much George.

I have started the 100Days SwiftUI program. And that program starts working with the fundamentals in playground files, which is why I am creating playground files.

From what you are saying, I gather what you mean is Xcode can not have two files from two different projects to open within the same window? So the suggestion you made is to create two files in the same project, so they are both available to open in the same window within the project navigation area. Okay, I just tried. I guess that is a workaround.

What's important is clear from this that the Xcode editor can't open two files from two different projects in the same window, and those two files from the same project can't be playground files. I guess if that is the Editor's constraint and requirement, it's good to simply know for sure and not wondering.

Thanks once again! Nicole

2      

Ohhh I see why you would want that. It's not a bad idea I guess. Paul uses the playground for the basics for about 14 days then the rest of the 86 days is on the Xcode projects. So don't worry you'll have multiple files and tabs coming out of your ears in no time. Just follow his tips/advice you'll do well.

George

3      

I'm also using Xcode a playground to create notes and practice writing code while reviewing the first 15 days of 100 Days. What I've been doing is creating individual playground pages for each day/checkpoint.

If you have the left-hand Navigator panel open and are displaying the Project Navigator for your playground, right-click the name of the playground and choose 'New Playground Page' from the pop-up menu.

2      

Yeah, I would also love to be able to do this --- coming from a Smalltalk background, where the concept of "Playgrounds" (which we used to call Workspaces) was invented (back in the 1980s no less), there is a common pattern to use Playgrounds as a kind of notebook for your work. You basically do a batch of sample code when learning a new feature, then archive that as a reference.

It's also helpful when debugging other pre-existing code. People do some amazingly odd things with anonymous functions, for example, and it's very helpful to have all that annotated with your own examples so that you can untangle the whole thing.

It looks to me like tabs in Playgrounds on Xcode is currently a partially implemented feature that doesn't work. If you open two new Playgrounds in separate windows, then drag the tab bar from one to the other, it is actually accepted --- but it just creates a duplicate of the tab in the target, and weird behaviour ensues.

Let's hope it's a thing for Xcode 16!

1      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.