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/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/.vscode/tasks.json b/.vscode/tasks.json index 4f69dc4..defb48a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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", @@ -43,7 +51,11 @@ "-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" ], @@ -51,7 +63,7 @@ "kind": "build", "isDefault": true }, - "dependsOn": ["xcodegen"] + "dependsOn": ["xcodegen", "clean"] } ] } 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 71% rename from Package.swift rename to Main/Package.swift index 6994b3f..e694228 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:` @@ -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,9 +30,15 @@ let package = Package( condition: .when(platforms: [ .iOS ]) + ), + .byNameItem( + name: "HotReloading", + condition: .when(platforms: [ + .iOS + ]) ) ], - path: packageName + path: "Sources" ) ] ) diff --git a/Demo/ContentView.swift b/Main/Sources/ContentView.swift similarity index 55% rename from Demo/ContentView.swift rename to Main/Sources/ContentView.swift index 3cfede2..48523f1 100644 --- a/Demo/ContentView.swift +++ b/Main/Sources/ContentView.swift @@ -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) @@ -19,9 +23,3 @@ struct ContentView: View { @ObserveInjection var inject #endif } - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -} 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`) 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