• Stars
    star
    536
  • Rank 82,794 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hot reloading as a Swift Package

Yes, HotReloading for Swift, Objective-C & C++!

This project is the InjectionIII app for live code updates available as a Swift Package. i.e.:

Icon

Then, you can inject function implementations without having to rebuild your app... Icon

To try out an example project that is already set-up, clone this fork of SwiftUI-Kit.

To use on your project, add this repo as a Swift Package and add "Other Linker Flags": -Xlinker -interposable. You no longer need to add a "Run Script" build phase. If want to inject on a device, see the notes below on how to configure the InjectionIII app. Note however, on an M1/M2 Mac this project only works with an iOS/tvOS 14 or later simulator. Also, due to a quirk of how Xcode how enables a DEBUG build of Swift Packages, your "configuration" needs to contain the string "Debug".

Remember not to release your app with this package configured.

You should see a message that the app is watching for source file changes in your home directory. You can change this scope by adding comma separated list in the environment variable INJECTION_DIRECTORIES. Should you want to connect to the InjectionIII.app when using the simulator, add the environment variable INJECTION_DAEMON to your scheme.

Consult the README of the InjectionIII project for more information in particular how to use it to inject SwiftUI using the HotSwiftUI protocol extension.

HotReloading using VSCode

It's possible to use HotReloading from inside the VSCode editor and realise a form of "VScode Previews". Consult this project for the setup required.

Device Injection

This version of the HotReloading project and it's dependencies now support injection on a real iOS or tvOS device.

Device injection now connects to the InjectionIII.app (github release 4.6.0 or above) and requires you type the following commands into a Terminal then restart the app to opt into receiving remote connections from a device:

$ rm ~/Library/Containers/com.johnholdsworth.InjectionIII/Data/Library/Preferences/com.johnholdsworth.InjectionIII.plist
$ defaults write com.johnholdsworth.InjectionIII deviceUnlock any

Note, if you've used the App Store version of InjectionIII in the past, the binary releases have a different preferences file and the two can get confused and prevent writing this preference from taking effect. This is why the first rm command above can be necessary. If your device doesn't connect check the app is listening on port 8899:

% netstat -an | grep LIST | grep 88
tcp4       0      0  127.0.0.1.8898         *.*                    LISTEN
tcp4       0      0  *.8899                 *.*                    LISTEN

If your device still doesn't connect either add an INJECTION_HOST environment variable to your scheme containg the WiFi IP address of the host you're running the InjectionIII.app on or clone this project and code your mac's IP address into the hostname variable in Package.swift. Then, drag the clone onto your project to have it take the place of the configured Swift Package as outlined in these instructions.

Note: as the HotReloading package needs to connect a network socket to your Mac to receive commands and new versions of code, expect a message the first time you run your app after adding the package asking you to "Trust" that your app should be allowed to do this. Likewise, at the Mac end (as the InjectionIII app needs to open a network port to accept this connection) you may be prompted for permission if you have the macOS firewall turned on.

For SwiftUI you can force screen updates by following the conventions outlined in the HotSwiftUI project then you can experience something like "Xcode Previews", except for a fully functional app on an actual device!

Vapor injection

To use injection with Vapor web server, add this Swift package as a dependency to its Package.swift and as dependency of the "App" target then run vapour from inside Xcode. It will ask you to run a script to start the associated daemon processes which watches for source file changes from inside project directory. It's not possible to inject closures that have already been registered with routes however but if you delegate their implementation to the method of a class it can be injected.

Thanks to...

The App Tracing functionality uses the OliverLetterer/imp_implementationForwardingToSelector trampoline implementation via the SwiftTrace project under an MIT license.

SwiftTrace uses the very handy https://github.com/facebook/fishhook as an alternative to the dyld_dynamic_interpose dynamic loader private api. See the project source and header file included in the framework for licensing details.

The "Remote" server in this project which allows you to capture videos from your device includes code adapted from acj/TimeLapseBuilder-Swift

This release includes a very slightly modified version of the excellent canviz library to render "dot" files in an HTML canvas which is subject to an MIT license. The changes are to pass through the ID of the node to the node label tag (line 212), to reverse the rendering of nodes and the lines linking them (line 406) and to store edge paths so they can be coloured (line 66 and 303) in "canviz-0.1/canviz.js".

It also includes CodeMirror JavaScript editor for the code to be evaluated in the Xprobe browser under an MIT license.

$Date: 2023/06/10 $

More Repositories

1

injectionforxcode

Runtime Code Injection for Objective-C & Swift
Objective-C
6,551
star
2

InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
Objective-C
3,995
star
3

Xtrace

Trace Objective-C method calls by class or instance
Objective-C++
1,832
star
4

Refactorator

Xcode Plugin that Refactors Swift & Objective-C
Swift
991
star
5

GitDiff

Highlights deltas against git repo in Xcode
Objective-C
891
star
6

Remote

Control your iPhone from inside Xcode for end-to-end testing.
Objective-C
853
star
7

SwiftTrace

Trace Swift and Objective-C method invocations
Swift
695
star
8

XprobePlugin

Live Memory Browser for Apps & Xcode
Objective-C++
395
star
9

RefactoratorApp

App version of Refactorator plugin
Swift
255
star
10

Accelerator

Inline frameworks of Swift CocoaPods projects for faster launch
Ruby
174
star
11

InjectionApp

Issue Tracking Repo for Injection as an App
Swift
111
star
12

Fortify

Making Swift more robust
Swift
95
star
13

HotSwiftUI

Utilities for Hot Reloading SwiftUI apps.
Swift
94
star
14

Diamond

Diamond - Swift scripting made easy
Objective-C
94
star
15

SwiftPython

Experiments in bridging Swift to Python
Swift
88
star
16

Dynamo

High Performance (nearly)100% Swift Web server supporting dynamic content.
Swift
68
star
17

SwiftRegex

Some regular expression operators for Swift
Swift
67
star
18

NSLinux

NSString and libdispatch compatibility code for Swift on Linux
Swift
47
star
19

InstantSyntax

SwiftSyntax binary frameworks
Swift
47
star
20

InjectionNext

Fourth evolution of Code Injection for Xcode
Swift
47
star
21

WatchkitCurrency

Swift Currency Convertor for iWatch with flexible interface
Swift
40
star
22

TwoWayMirror

Adapt Swift’s Mirror functionality to make it bidirectional.
Swift
38
star
23

InjectionLite

Swift package re-write of InjectionIII app
Swift
34
star
24

Smuggler

Smuggle code bundles into an app running in the Simulator
Objective-C++
32
star
25

SwiftRegex5

5th incarnation of Swift Regex library using generic subscripts
Swift
32
star
26

SwiftAspects

Experiments in Aspects with Swift (Xtrace for Swift)
Assembly
30
star
27

unhide

export symbols with “hidden” visibility for Swift frameworks
Objective-C++
25
star
28

Symbolicate

Symbolicate for OS X
Objective-C
23
star
29

DLKit

A rather subscript oriented interface to the dynamic linker.
Swift
22
star
30

SwiftTryCatch

Try/Catch for Swift?
Swift
15
star
31

ApportablePlugin

Simple Plugin for work with Apportable
Objective-C
14
star
32

Compilertron

InjectionIII for the Swift compiler
C++
14
star
33

SearchLight

SpotLight on Steroids
Objective-C++
14
star
34

siteify

Build web site from a project’s Swift sources.
HTML
13
star
35

SwiftPlugin

A way to import classes from plugins
Swift
12
star
36

SwiftKeyPath

valueForKeyPath: for Swift
Swift
12
star
37

DynamoLinux

100% Swift Linux Web Server
Swift
11
star
38

ProfileSwiftUI

InstrumentSwiftUI
Swift
10
star
39

SwiftUIPlaygrounds

Alternative to Xcode previews.
Swift
9
star
40

SwiftRegex4

Basic regex operations for Swift4
Swift
9
star
41

StringIndex

Sensible indexing into Swift Strings
Swift
8
star
42

SwiftView

Curated Xcode Project as a means of navigating Swift Sources
7
star
43

Parallel

Some primitives for concurrent processing
Swift
6
star
44

Popen

Reading and writing processes and files
Swift
6
star
45

WatchkitSundial

Sundial for Apple Watch
Objective-C
6
star
46

SwiftierJSON

Memory efficient version of SwiftyJSON
Swift
6
star
47

objectivecpp

HTML
5
star
48

YieldGenerator

Python's "yield" generators for Swift
Swift
5
star
49

opaqueify

Greater use of Opaque types (SE0335)
Swift
5
star
50

SwiftMock

Mock structs and classes without code modification for testing.
Swift
4
star
51

Unwrap

Self documenting alternatives to force unwrap operator.
Swift
4
star
52

InjectionScratch

InjectionScratch
Objective-C++
3
star
53

EasyPointer

Rounding off some of the rough edges of Swift's pointer model
Swift
2
star
54

TestRunner

Example of calling Swift methods using name pattern (XCTest?)
Swift
2
star
55

binary-Swallow0

Swift
1
star
56

Character

Integer conversions and operators for Swift Characters.
Swift
1
star
57

ASCII

Facilitating operations on ASCII in Swift
Swift
1
star