最近几年很少写原生的iOS程序,写的多的是 React Native
和Flutter
,他们都支持Hot Reloading, 不用重新运行就能看到最新的UI效果。相比之下Xcode
真的逊色很多,最近写SwiftUI
尝试了一下Preview 功能,实在是太弱鸡了,Google了一下解决方案,还真有Xcode Hot Reloading。记录一下。
github InjectionIII
github Inject
AppStore
下载 InjectionIIIInjectionIII
, 在桌面是看不到InjectoinIII
窗口的,点击状态栏图标,选择Open Project,选择项目目录File Watcher
选项, 选择的项目会在Open Recent
中展示File → Swift Packages → Add Package Dependency
, 输入Inject
查找, 添加packageTarget
中设置 Other Linker Flag
, 添加-Xlinker -interposable
@ObservedObject private var iO = Inject.observer
变量.enableInjection()
import SwiftUI
import Inject
struct ContentView: View {
@ObservedObject private var iO = Inject.observer
var body: some View {
Text("Hello, !")
.padding()
.enableInjection()
}
}
💉 InjectionIII connected /Demo/SwiftUI_Widget/SwiftUI_Widget.xcodeproj
💉 Watching files under /Demo/SwiftUI_Widget
💉 💉 ⚠️ Your project file seems to be in the Desktop or Documents folder and may prevent InjectionIII working as it has special permissions.
💉 Compiling /Demo/SwiftUI_Widget/SwiftUI_Widget/ContentView.swift
💉 Loading .dylib ...
💉 Loaded .dylib - Ignore any duplicate class warning ⬆️
💉 Interposed 3 function references.
💉 Injected type #1 'SwiftUI_Widget.ContentView'
💉 Injected type #2 'SwiftUI_Widget.ContentView_Previews'