From 25aaeb5702c6d9390cc7a1625f9b779c0c396819 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 14:38:27 +0100 Subject: [PATCH 1/7] Move `Package` to `Main` directory. --- Application/Application.swift | 1 + Package.swift => Main/Package.swift | 4 ++-- {Demo => Main/Sources}/ContentView.swift | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) rename Package.swift => Main/Package.swift (93%) rename {Demo => Main/Sources}/ContentView.swift (74%) diff --git a/Application/Application.swift b/Application/Application.swift index e48dfb6..83f1ef1 100644 --- a/Application/Application.swift +++ b/Application/Application.swift @@ -1,4 +1,5 @@ import SwiftUI +import Main #if DEBUG @_exported import Inject diff --git a/Package.swift b/Main/Package.swift similarity index 93% rename from Package.swift rename to Main/Package.swift index 6994b3f..1f472d6 100644 --- a/Package.swift +++ b/Main/Package.swift @@ -3,7 +3,7 @@ import PackageDescription -let packageName = "Demo" +let packageName = "Main" // Necessary for `sourcekit-lsp` support in VSCode:` @@ -31,7 +31,7 @@ let package = Package( ]) ) ], - path: packageName + path: "Sources" ) ] ) diff --git a/Demo/ContentView.swift b/Main/Sources/ContentView.swift similarity index 74% rename from Demo/ContentView.swift rename to Main/Sources/ContentView.swift index 3cfede2..b2fc4f6 100644 --- a/Demo/ContentView.swift +++ b/Main/Sources/ContentView.swift @@ -4,10 +4,15 @@ 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) From 80b98f80c6e4ec64b1c8f74b7485c4d93b65d2f2 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 14:39:27 +0100 Subject: [PATCH 2/7] Adding packages to Swift package rather than Xcodegen. --- Main/Package.swift | 9 ++++++++- project.yml | 13 ++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Main/Package.swift b/Main/Package.swift index 1f472d6..e694228 100644 --- a/Main/Package.swift +++ b/Main/Package.swift @@ -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( @@ -29,6 +30,12 @@ let package = Package( condition: .when(platforms: [ .iOS ]) + ), + .byNameItem( + name: "HotReloading", + condition: .when(platforms: [ + .iOS + ]) ) ], path: "Sources" diff --git a/project.yml b/project.yml index d73cd9b..2703060 100644 --- a/project.yml +++ b/project.yml @@ -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 From a55c216b75ecb74fdc740afe1a4481fb2d368693 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 14:39:54 +0100 Subject: [PATCH 3/7] Update Swift build dependencies task directory. --- .vscode/tasks.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4f69dc4..28ee4d0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -24,7 +24,10 @@ "-target", "-Xswiftc", "arm64-apple-ios13.0-simulator" - ] + ], + "options": { + "cwd": "${workspaceFolder}/Main" + } }, { "label": "xcodegen", From ccc07652404f2658a14255ba3eabcc46e8e12c9b Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 19:44:20 +0100 Subject: [PATCH 4/7] Unused `xcodebuild` arguments. --- .vscode/tasks.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 28ee4d0..323c9e7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -47,6 +47,10 @@ "${command:ios-debug.targetSdk}", "-derivedDataPath", "~/Library/Developer/Xcode/DerivedData/Demo-avuzscipzqxczrbltxhlvbnxujdo", // <- use `BUILD_DIR`? + // "-clonedSourcePackagesDirPath", + // "./Main/.build", + // "-resultBundlePath", + // "./ResultBundlePath", "-allowProvisioningUpdates", "ARCHS=arm64" ], From d6be4f22dd6a2a751deed6354550cfab6368d0b7 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 20:22:17 +0100 Subject: [PATCH 5/7] Passing `resultBundlePath` xcodebuild argument means we no longer need to use hashed derived directory. --- .vscode/launch.json | 2 +- .vscode/tasks.json | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8cce4a5..855f76f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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}" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 323c9e7..defb48a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -34,6 +34,11 @@ "type": "process", "command": "xcodegen" }, + { + "label": "clean", + "type": "shell", + "command": "rm -R -f ~/Library/Developer/Xcode/DerivedData/Demo/Result.xcresult" + }, { "label": "xcodebuild", "type": "process", @@ -46,11 +51,11 @@ "-sdk", "${command:ios-debug.targetSdk}", "-derivedDataPath", - "~/Library/Developer/Xcode/DerivedData/Demo-avuzscipzqxczrbltxhlvbnxujdo", // <- use `BUILD_DIR`? - // "-clonedSourcePackagesDirPath", - // "./Main/.build", - // "-resultBundlePath", - // "./ResultBundlePath", + "~/Library/Developer/Xcode/DerivedData/Demo", // <- use `BUILD_DIR`? + "-clonedSourcePackagesDirPath", + "./Main/.build", + "-resultBundlePath", + "~/Library/Developer/Xcode/DerivedData/Demo/Result.xcresult", "-allowProvisioningUpdates", "ARCHS=arm64" ], @@ -58,7 +63,7 @@ "kind": "build", "isDefault": true }, - "dependsOn": ["xcodegen"] + "dependsOn": ["xcodegen", "clean"] } ] } From 8bfdebf08bca4a9b54929619675459364cdec37d Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 18 Jun 2022 20:22:36 +0100 Subject: [PATCH 6/7] Update `README.md` to remove `HotReloading` section. --- README.md | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/README.md b/README.md index 58bca2a..0989d7a 100644 --- a/README.md +++ b/README.md @@ -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`) From 0a0380983cd37287b7f746e9ad808b023428e198 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Sat, 16 Dec 2023 08:07:37 +1100 Subject: [PATCH 7/7] Remove preview provider. --- .vscode/settings.json | 2 +- Main/Sources/ContentView.swift | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1970744..3acd0c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "[swift]": { diff --git a/Main/Sources/ContentView.swift b/Main/Sources/ContentView.swift index b2fc4f6..48523f1 100644 --- a/Main/Sources/ContentView.swift +++ b/Main/Sources/ContentView.swift @@ -5,7 +5,6 @@ import Inject #endif public struct ContentView: View { - public init() { } @@ -24,9 +23,3 @@ public struct ContentView: View { @ObserveInjection var inject #endif } - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -}