Now that Xcode 12 supports Swift Packages for playgrounds, I thought it was time to expand
xcopen to build not only playgrounds but also allow you to embed them in workspaces.
xcopen in a nutshell
If you’re not familiar with
xcopen (I’ve only mentioned it briefly on this website), it’s my answer to
xed. It does what
xed does more or less and adds more features that I use a lot.
xcopen to handle command-line activities that I regularly perform during development. If you run it without arguments, it looks for a workspace and then opens that. If no workspace is found, it looks for xcode projects and playgrounds. If you pass it file names and paths, it opens those instead.
OVERVIEW: xcopen ... Open files in Xcode. xcopen docs Open .md and .txt files. xcopen new Create new files (if they don't exist), open in Xcode. xcopen xc|ws|pg(w) Open xcodeproj, workspace, or playground. * Add ios|mac|tvos to create playground. * Add w (pgw) to create playground in workspace. xcopen pkg|xpkg Open Package.swift in TextEdit or Xcode. USAGE: xcopen [ ...] [--background] [--folder] [--open] [--no-open] ARGUMENTS: Files to open. If blank, opens xcworkspace or,if not found, searches for xcodeproj. OPTIONS: -b, -g, --background Open Xcode in the background -f, -e, --folder Enclose new items in folder --open/--no-open Open newly created playgrounds/workspaces (default: true) -h, --help Show help information.
Shortcuts let you gather up your docs (like README.md, CHANGELOG.md, and LICENSE.txt) and open them together for edits.
You control whether Xcode opens in the foreground or background, enabling you to keep working without Xcode taking up your immediate attention.
Recently, I added support for playground creation. Need a Mac playground?
xcopen pg mac. It emulates Finder naming so there won’t be naming conflicts. Instead, it builds
macOS 3, etc as your root playground names. Based on feedback from my Twitterati pals (waves hi!), I added a flag that lets you group them together in a subfolder if you don’t want multiple playgrounds cluttering your working directory.
Today, I decided to start working with Swift packages, so I added workspace creation:
xcopen pgw mac --folder
pgw builds both a playground and an associated workspace. Adding
--folder embeds them both into a new folder. Otherwise they are created in the working directory.
Using Swift Package Support
Add any folder containing a Swift Package to your workspace:
- Files > Add files to workspace name (may be greyed out); or
- Project navigator contextual pop-up > Add files to workspace name; or
- Or just drag the folder above your playground entry in the Project navigator to ensure you’re not adding it directly to your playground.
If your package has dependencies, they’re listed in the Project navigator.
Next, try importing the new package. If it doesn’t autocomplete, quit and restart Xcode and re-open your workspace. For some reason, in this early beta it doesn’t seem to get picked up immediately.
Then test out the functionality you’ve imported. In the following example, I’m using a custom exponentiation operator:
xcopen a lot these days, tooling it to make my workday easier. If you find a feature you think I should include please open an issue at github. And if you like the utility, do let me know. Thanks!
The easiest way to install
xcopen is via
mint, which you can install with
brew. Once you have mint, all you have to say is
mint install erica/xcopen.
Comments are closed.