Skip to content

Commit 75efab0

Browse files
authored
Add SwiftPM based example (#24)
1 parent 77071bd commit 75efab0

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ xcuserdata/
55
DerivedData/
66
.swiftpm/configuration/registries.json
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
Example/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
89
.netrc
910
/.build-*
10-
/Benchmarks/.build
11+
/Benchmarks/.build
12+
/Example/.build
13+
Example/Package.resolved

Example/Package.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import Foundation
5+
import PackageDescription
6+
7+
let exampleTarget = Target.executableTarget(
8+
name: "Example",
9+
dependencies: [
10+
.product(name: "OpenSwiftUI", package: "OpenSwiftUI"),
11+
],
12+
path: "Example",
13+
sources: ["ExampleApp.swift", "ContentView.swift"]
14+
)
15+
16+
let package = Package(
17+
name: "Example",
18+
platforms: [
19+
.macOS(.v10_15),
20+
],
21+
products: [.executable(name: "Example", targets: ["Example"])],
22+
dependencies: [
23+
.package(path: "../"),
24+
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
25+
],
26+
targets: [
27+
exampleTarget,
28+
]
29+
)
30+
31+
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
32+
guard let value = ProcessInfo.processInfo.environment[key] else {
33+
return defaultValue
34+
}
35+
if value == "1" {
36+
return true
37+
} else if value == "0" {
38+
return false
39+
} else {
40+
return defaultValue
41+
}
42+
}
43+
44+
#if os(macOS)
45+
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
46+
#else
47+
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH")
48+
#endif
49+
50+
extension Target {
51+
func addAGSettings() {
52+
// FIXME: Weird SwiftPM behavior for binary Target. Otherwize we'll get the following error message
53+
// "could not determine executable path for bundle 'AttributeGraph.framework'"
54+
dependencies.append(.product(name: "AttributeGraph", package: "OpenGraph"))
55+
56+
var swiftSettings = swiftSettings ?? []
57+
swiftSettings.append(.define("OPENGRAPH_ATTRIBUTEGRAPH"))
58+
self.swiftSettings = swiftSettings
59+
}
60+
}
61+
62+
if attributeGraphCondition {
63+
exampleTarget.addAGSettings()
64+
}

Sources/OpenSwiftUI/AppStructure/Scenes/TODO/WindowGroup.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Lastest Version: iOS 15.5
77
// Status: WIP
88

9-
#if canImport(Darwin)
109
@frozen
1110
public struct LocalizedStringKey {}
1211

@@ -58,4 +57,3 @@ public struct WindowGroup<Content>: Scene where Content: View {
5857

5958
var id: String?
6059
}
61-
#endif

0 commit comments

Comments
 (0)