Skip to content

Commit

Permalink
Merge pull request #3 from markst/issue/main-package
Browse files Browse the repository at this point in the history
Seperate Application into swift package
  • Loading branch information
markst authored Dec 15, 2023
2 parents d3f8a93 + 0a03809 commit 71b8835
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"name": "Launch",
"type": "lldb",
"request": "launch",
"program": "~/Library/Developer/Xcode/DerivedData/Demo-avuzscipzqxczrbltxhlvbnxujdo/Build/Products/Debug-${command:ios-debug.targetSdk}/Demo.app",
"program": "~/Library/Developer/Xcode/DerivedData/Demo/Build/Products/Debug-${command:ios-debug.targetSdk}/Demo.app",
"iosBundleId": "dev.mt.Demo",
"iosTarget": "select",
"preLaunchTask": "${defaultBuildTask}"
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},

"[swift]": {
Expand Down
18 changes: 15 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
"-target",
"-Xswiftc",
"arm64-apple-ios13.0-simulator"
]
],
"options": {
"cwd": "${workspaceFolder}/Main"
}
},
{
"label": "xcodegen",
"type": "process",
"command": "xcodegen"
},
{
"label": "clean",
"type": "shell",
"command": "rm -R -f ~/Library/Developer/Xcode/DerivedData/Demo/Result.xcresult"
},
{
"label": "xcodebuild",
"type": "process",
Expand All @@ -43,15 +51,19 @@
"-sdk",
"${command:ios-debug.targetSdk}",
"-derivedDataPath",
"~/Library/Developer/Xcode/DerivedData/Demo-avuzscipzqxczrbltxhlvbnxujdo", // <- use `BUILD_DIR`?
"~/Library/Developer/Xcode/DerivedData/Demo", // <- use `BUILD_DIR`?
"-clonedSourcePackagesDirPath",
"./Main/.build",
"-resultBundlePath",
"~/Library/Developer/Xcode/DerivedData/Demo/Result.xcresult",
"-allowProvisioningUpdates",
"ARCHS=arm64"
],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["xcodegen"]
"dependsOn": ["xcodegen", "clean"]
}
]
}
1 change: 1 addition & 0 deletions Application/Application.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import Main

#if DEBUG
@_exported import Inject
Expand Down
13 changes: 10 additions & 3 deletions Package.swift → Main/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import PackageDescription

let packageName = "Demo"
let packageName = "Main"

// Necessary for `sourcekit-lsp` support in VSCode:`

Expand All @@ -18,7 +18,8 @@ let package = Package(
.library(name: packageName, targets: [packageName])
],
dependencies: [
.package(url: "https://github.com/krzysztofzablocki/Inject.git", .branch("main"))
.package(url: "https://github.com/krzysztofzablocki/Inject.git", .branch("main")),
.package(url: "https://github.com/johnno1962/HotReloading.git", .branch("main"))
],
targets: [
.target(
Expand All @@ -29,9 +30,15 @@ let package = Package(
condition: .when(platforms: [
.iOS
])
),
.byNameItem(
name: "HotReloading",
condition: .when(platforms: [
.iOS
])
)
],
path: packageName
path: "Sources"
)
]
)
16 changes: 7 additions & 9 deletions Demo/ContentView.swift → Main/Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import SwiftUI
import Inject
#endif

struct ContentView: View {
var body: some View {
public struct ContentView: View {
public init() {

}

public var body: some View {
VStack {
Text("Hello World")
Text("Testing")
.padding()
.background(Color.red)
.border(.blue)
Expand All @@ -19,9 +23,3 @@ struct ContentView: View {
@ObserveInjection var inject
#endif
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@ Demonstrating vscode development environment using xcodegen + HotReloading.
- SwiftUI injection property wrapper with [Inject](https://github.com/krzysztofzablocki/Inject.git)

![hotreloading-vscode-ios 2022-06-03 20_10_56](https://user-images.githubusercontent.com/274318/171922061-cabbb0aa-b2ba-4ade-a606-41a06c3c2ca3.gif)

## Support HotReloading

One caveat to support HotReloading is to ensure the `derivedDataPath` passed to `xcodebuild` matches that when building with Xcode.

Xcode (by default) uses "Unique" build locations for each project: [Xcode DerivedData Hashes](https://pewpewthespells.com/blog/xcode_deriveddata_hashes.html)

Once the `xcodegen` task has been run the following command can be used to output the `$BUILT_PRODUCTS_DIR` including the unique location (for this demo):

```shell
$xcodebuild -project ./Demo.xcodeproj -scheme Demo -showBuildSettings | grep -m 1 "BUILT_PRODUCTS_DIR" | grep -oEi "\/.*"
```

Output:

```
~/Library/Developer/Xcode/DerivedData/Demo-avuzscipzqxczrbltxhlvbnxujdo/Build/Products/Debug-iphoneos
```

This in turn means the `.vscode/launch.json` iOS Debug `program` needs to be updated to resolve to the output `*.app` (`$CODESIGNING_FOLDER_PATH`)
13 changes: 4 additions & 9 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ name: Demo
options:
bundleIdPrefix: dev.mt
packages:
HotReloading:
url: https://github.com/johnno1962/HotReloading.git
branch: main
Inject:
url: https://github.com/krzysztofzablocki/Inject.git
branch: main
Main:
path: ./Main
targets:
Demo:
type: application
platform: iOS
deploymentTarget: "14.0"
sources: [Application, Demo]
sources: [Application]
dependencies:
- sdk: SwiftUI.framework
- package: HotReloading
- package: Inject
- package: Main
settings:
base:
CURRENT_PROJECT_VERSION: 1
Expand Down

0 comments on commit 71b8835

Please sign in to comment.