Skip to content

Commit abecc5c

Browse files
committed
Adding Example.swiftpm Swift Playgrounds App Project With ExampleKit Library
1 parent 6a53e7e commit abecc5c

File tree

9 files changed

+169
-1
lines changed

9 files changed

+169
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CachedManifest</key>
6+
<dict>
7+
<key>manifestData</key>
8+
<data>
9+
eyJkZXBlbmRlbmNpZXMiOltdLCJkaXNwbGF5TmFtZSI6IlRlc3RlciIsInBh
10+
Y2thZ2VLaW5kIjp7InJvb3QiOnt9fSwicGxhdGZvcm1zIjpbeyJvcHRpb25z
11+
IjpbXSwicGxhdGZvcm1OYW1lIjoiaW9zIiwidmVyc2lvbiI6IjE2LjAifV0s
12+
InByb2R1Y3RzIjpbeyJuYW1lIjoiVGVzdGVyIiwic2V0dGluZ3MiOlt7ImRp
13+
c3BsYXlWZXJzaW9uIjpbIjEuMCJdfSx7ImJ1bmRsZVZlcnNpb24iOlsiMSJd
14+
fSx7ImlPU0FwcEluZm8iOlt7ImFjY2VudENvbG9yIjp7InByZXNldENvbG9y
15+
Ijp7InByZXNldENvbG9yIjp7InJhd1ZhbHVlIjoiYnJvd24ifX19LCJhcHBJ
16+
Y29uIjp7InBsYWNlaG9sZGVyIjp7Imljb24iOnsicmF3VmFsdWUiOiJ0diJ9
17+
fX0sImNhcGFiaWxpdGllcyI6W10sInN1cHBvcnRlZERldmljZUZhbWlsaWVz
18+
IjpbInBhZCIsInBob25lIl0sInN1cHBvcnRlZEludGVyZmFjZU9yaWVudGF0
19+
aW9ucyI6W3sicG9ydHJhaXQiOnt9fSx7ImxhbmRzY2FwZVJpZ2h0Ijp7fX0s
20+
eyJsYW5kc2NhcGVMZWZ0Ijp7fX0seyJwb3J0cmFpdFVwc2lkZURvd24iOnsi
21+
Y29uZGl0aW9uIjp7ImRldmljZUZhbWlsaWVzIjpbInBhZCJdfX19XX1dfV0s
22+
InRhcmdldHMiOlsiQXBwTW9kdWxlIl0sInR5cGUiOnsiZXhlY3V0YWJsZSI6
23+
bnVsbH19XSwidGFyZ2V0TWFwIjp7IkFwcE1vZHVsZSI6eyJkZXBlbmRlbmNp
24+
ZXMiOltdLCJleGNsdWRlIjpbXSwibmFtZSI6IkFwcE1vZHVsZSIsInBhdGgi
25+
OiIuIiwicmVzb3VyY2VzIjpbXSwic2V0dGluZ3MiOlt7ImtpbmQiOnsiZW5h
26+
YmxlVXBjb21pbmdGZWF0dXJlIjp7Il8wIjoiQmFyZVNsYXNoUmVnZXhMaXRl
27+
cmFscyJ9fSwidG9vbCI6InN3aWZ0In1dLCJ0eXBlIjoiZXhlY3V0YWJsZSJ9
28+
fSwidGFyZ2V0cyI6W3siZGVwZW5kZW5jaWVzIjpbXSwiZXhjbHVkZSI6W10s
29+
Im5hbWUiOiJBcHBNb2R1bGUiLCJwYXRoIjoiLiIsInJlc291cmNlcyI6W10s
30+
InNldHRpbmdzIjpbeyJraW5kIjp7ImVuYWJsZVVwY29taW5nRmVhdHVyZSI6
31+
eyJfMCI6IkJhcmVTbGFzaFJlZ2V4TGl0ZXJhbHMifX0sInRvb2wiOiJzd2lm
32+
dCJ9XSwidHlwZSI6ImV4ZWN1dGFibGUifV0sInRvb2xzVmVyc2lvbiI6eyJf
33+
dmVyc2lvbiI6IjUuOC4wIn19
34+
</data>
35+
<key>manifestHash</key>
36+
<data>
37+
o/2SAQhG8wuJDiy/CmuIRjAyhUX68Cw+Zx7B3TQRyWg=
38+
</data>
39+
<key>schemaVersion</key>
40+
<integer>4</integer>
41+
<key>swiftPMVersionString</key>
42+
<string>5.8.0</string>
43+
</dict>
44+
</dict>
45+
</plist>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>DocumentThumbnailConfiguration</key>
6+
<dict>
7+
<key>accentColorHash</key>
8+
<data>
9+
XrZ/n4QJucP3OXNWM8vfkhITk9DhO9D0ZLGypqFa0tw=
10+
</data>
11+
<key>appIconHash</key>
12+
<data>
13+
pG5dK74tOwWy0otgVNmMGARrziiJPQTgUHJBaBFtVYc=
14+
</data>
15+
<key>thumbnailIsPrerendered</key>
16+
<false/>
17+
</dict>
18+
</dict>
19+
</plist>
63.2 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AppSettings</key>
6+
<dict>
7+
<key>appIconPlaceholderGlyphName</key>
8+
<string>tv</string>
9+
<key>appSettingsVersion</key>
10+
<integer>1</integer>
11+
</dict>
12+
</dict>
13+
</plist>

Package.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// swift-tools-version: 5.8
2+
3+
// WARNING:
4+
// This file is automatically generated.
5+
// Do not edit it by hand because the contents will be replaced.
6+
7+
import PackageDescription
8+
import AppleProductTypes
9+
10+
let package = Package(
11+
name: "Example",
12+
platforms: [
13+
.iOS("16.0")
14+
],
15+
products: [
16+
.library(
17+
name: "ExampleKit",
18+
targets: ["ExampleKit"]
19+
),
20+
.iOSApplication(
21+
name: "ExampleApp",
22+
targets: ["ExampleAppModule"],
23+
displayVersion: "1.0",
24+
bundleVersion: "1",
25+
appIcon: .placeholder(icon: .tv),
26+
accentColor: .presetColor(.brown),
27+
supportedDeviceFamilies: [
28+
.pad,
29+
.phone
30+
],
31+
supportedInterfaceOrientations: [
32+
.portrait,
33+
.landscapeRight,
34+
.landscapeLeft,
35+
.portraitUpsideDown(.when(deviceFamilies: [.pad]))
36+
]
37+
)
38+
],
39+
targets: [
40+
.target(
41+
name: "ExampleKit",
42+
dependencies: []
43+
),
44+
.executableTarget(
45+
name: "ExampleAppModule",
46+
dependencies: ["ExampleKit"],
47+
swiftSettings: [
48+
.enableUpcomingFeature("BareSlashRegexLiterals")
49+
]
50+
)
51+
]
52+
)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# In-App Libraries for Swift Playgrounds
1+
# In-App Libraries for Swift Playgrounds
22

33
Since the addition of App projects in **Swift Playgrounds 4** it’s been easy to use libraries in Swift packages hosted online in your Apps, but it hasn’t been easy or clear how to *create* libraries for reuse using **Swift Playgrounds**.
44

@@ -61,6 +61,7 @@ If your GitHub repository is Private, you can create a personal access token tha
6161
### Required Changes to Package Manifest
6262

6363
The `Package.swift` file needs to have the product and target for your library that was added, but needs to NOT have a `AppModule` target. You can either remove the `AppModule` target (and the `iOSApplication` product that references it) or you can change the name of the `AppModule` target (and all references to it, including the directory in `Sources` with all your application’s code). **Important**: If your Package.swift includes the `AppModule` then **Swift Playgrounds** will not let you add that package as a dependency because it conflicts with the `AppModule` target of the app in which you’re trying to add it.
64+
6465
```swift
6566
// swift-tools-version: 5.8
6667
import PackageDescription
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import SwiftUI
2+
3+
struct ContentView: View {
4+
var body: some View {
5+
VStack {
6+
Image(systemName: "globe")
7+
.imageScale(.large)
8+
.foregroundColor(.accentColor)
9+
Text("Hello, world!")
10+
}
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import SwiftUI
2+
3+
@main
4+
struct MyApp: App {
5+
var body: some Scene {
6+
WindowGroup {
7+
ContentView()
8+
}
9+
}
10+
}

Sources/ExampleKit/Example.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Swift
2+
3+
//public type will be visible from AppModule, but cannot
4+
//be initialized because the implicit init is internal
5+
public struct BareExample {}
6+
7+
//public init makes this one usable
8+
public struct InitableExample {
9+
public init() {}
10+
}
11+
12+
//internal (the default protection level) type will not be visible from AppModule
13+
struct InternalExample {}
14+
15+
//private types are obviously not visible to AppModule
16+
private struct PrivateExample {}

0 commit comments

Comments
 (0)