Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate Application into swift package #3

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was looking into passing Xcode project has as an argument:
microsoft/vscode#69027

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

started making a command line tool to generate hash:
https://github.com/markst/xcode-project-hashes

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does seem like best idea is to go about creating an extension: #4

"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