Skip to content

Instantly share code, notes, and snippets.

@finestructure
Last active August 12, 2020 01:19
Show Gist options
  • Save finestructure/1144f5390a18e12f31412e4c2d453bf8 to your computer and use it in GitHub Desktop.
Save finestructure/1144f5390a18e12f31412e4c2d453bf8 to your computer and use it in GitHub Desktop.
Make a playground with access to an SPM library ready for importing
#!/usr/bin/env bash
set -eux
PROJ_NAME=myproj2
PKG_URL=https://github.com/johnsundell/plot.git
PKG_FROM=0.1.0
LIB_NAME=Plot
SWIFT_VERSION=5.1.3
PLATFORM=macos
rm -rf $PROJ_NAME
mkdir $PROJ_NAME
cd $PROJ_NAME
swiftenv local $SWIFT_VERSION
swift package init
# add package
cat <<EOF > Package.swift
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "$PROJ_NAME",
products: [
.library(name: "$PROJ_NAME", targets: ["$PROJ_NAME"]),
],
dependencies: [
.package(url: "$PKG_URL", from: "$PKG_FROM")
],
targets: [
.target(name: "$PROJ_NAME", dependencies: ["$LIB_NAME"]),
]
)
EOF
# generate xcodeproj
swift package generate-xcodeproj
# make workspace
mkdir $PROJ_NAME.xcworkspace
cat <<EOF > $PROJ_NAME.xcworkspace/contents.xcworkspacedata
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:MyPlayground.playground">
</FileRef>
<FileRef
location = "container:$PROJ_NAME.xcodeproj">
</FileRef>
</Workspace>
EOF
# add playground
mkdir MyPlayground.playground
echo "import $LIB_NAME" > MyPlayground.playground/Contents.swift
cat <<EOF > MyPlayground.playground/contents.xcplayground
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='$PLATFORM'>
<timeline fileName='timeline.xctimeline'/>
</playground>
EOF
open $PROJ_NAME.xcworkspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment