Skip to content

Commit d394c53

Browse files
chore: drop namespace and rename symbols, closes #82
1 parent bb72d11 commit d394c53

5 files changed

Lines changed: 22 additions & 24 deletions

File tree

InjectHotReload.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "InjectHotReload"
3-
s.version = "1.3.1"
3+
s.version = "1.4.0"
44
s.summary = "Hot Reloading for Swift applications! "
55

66
s.homepage = "https://github.com/krzysztofzablocki/Inject"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ Just 2 steps to enable injection in your `SwiftUI` Views
8686

8787
> *Remember you **don't need** to remove this code when you are done, it's NO-OP in production builds.*
8888
89-
If you want to see your changes in action, you can enable an optional `Animation` variable on `Inject.animation` that will be used when ever new source code is injected into your application.
89+
If you want to see your changes in action, you can enable an optional `Animation` variable on `InjectConfiguration.animation` that will be used when ever new source code is injected into your application.
9090

9191
```swift
92-
Inject.animation = .interactiveSpring()
92+
InjectConfiguration.animation = .interactiveSpring()
9393
```
9494

9595
Using `Inject` is demoed in this [example app](https://github.com/MarcoEidinger/InjectSwiftUIExample)
@@ -99,8 +99,8 @@ For standard imperative UI frameworks we need a way to clean-up state between co
9999

100100
I create the concept of **Hosts** that work really well in that context, there are 2:
101101

102-
- `Inject.ViewControllerHost`
103-
- `Inject.ViewHost`
102+
- `ViewControllerHost`
103+
- `ViewHost`
104104

105105
How do we integrate this? We wrap the class we want to iterate on at the parent level, so we don’t modify the class we want to be injecting but we modify the parent callsite.
106106

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public protocol InjectListener {
1313
}
1414

1515
/// Public namespace for using Inject API
16-
public enum Inject {
16+
public enum InjectConfiguration {
1717
public static var bundlePath = "/Applications/InjectionIII.app/Contents/Resources/"
1818
@available(iOS 13.0, *)
1919
public static let observer = injectionObserver
@@ -26,7 +26,7 @@ public extension InjectListener {
2626
/// Ensures injection is enabled
2727
@inlinable @inline(__always)
2828
func enableInjection() {
29-
_ = Inject.load
29+
_ = InjectConfiguration.load
3030
}
3131
}
3232

@@ -59,10 +59,10 @@ private var loadInjectionImplementation: Void = {
5959

6060
#if targetEnvironment(simulator) || os(macOS) || targetEnvironment(macCatalyst)
6161

62-
if let bundle = Bundle(path: Inject.bundlePath + bundleName) {
62+
if let bundle = Bundle(path: InjectConfiguration.bundlePath + bundleName) {
6363
bundle.load()
6464
} else {
65-
print("⚠️ Inject: InjectionIII bundle not found, verify if it's in \(Inject.bundlePath)")
65+
print("⚠️ Inject: InjectionIII bundle not found, verify if it's in \(InjectConfiguration.bundlePath)")
6666
}
6767
#endif
6868
}()
@@ -75,7 +75,7 @@ public class InjectionObserver: ObservableObject {
7575
fileprivate init() {
7676
cancellable = NotificationCenter.default.publisher(for: Notification.Name("INJECTION_BUNDLE_NOTIFICATION"))
7777
.sink { [weak self] _ in
78-
if let animation = Inject.animation {
78+
if let animation = InjectConfiguration.animation {
7979
withAnimation(animation) {
8080
self?.injectionNumber += 1
8181
}

Sources/Inject/Integrations/Hosts.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ public typealias InjectViewType = NSView
1111

1212
#if DEBUG
1313

14-
extension Inject {
15-
public typealias ViewControllerHost = _InjectableViewControllerHost
16-
public typealias ViewHost = _InjectableViewHost
17-
}
14+
public typealias ViewControllerHost = _InjectableViewControllerHost
15+
public typealias ViewHost = _InjectableViewHost
1816

1917
/// Usage: to create an autoreloading view controller, wrap your
20-
/// view controller that you wish to see changes within `Inject.ViewHost`. For example,
18+
/// view controller that you wish to see changes within `ViewHost`. For example,
2119
/// If you are using a `TestViewController`, you would do the following:
22-
/// `let myView = Inject.ViewControllerHost(TestViewController())`
20+
/// `let myView = ViewControllerHost(TestViewController())`
2321
/// And within the parent view, you should add the view above.
2422
@dynamicMemberLookup
2523
open class _InjectableViewControllerHost<Hosted: InjectViewControllerType>: InjectViewControllerType {
@@ -113,9 +111,9 @@ open class _InjectableViewControllerHost<Hosted: InjectViewControllerType>: Inje
113111
}
114112

115113
/// Usage: to create an autoreloading view, wrap your
116-
/// view that you wish to see changes within `Inject.ViewHost`. For example,
114+
/// view that you wish to see changes within `ViewHost`. For example,
117115
/// If you are using a `TestView`, you would do the following:
118-
/// `let myView = Inject.ViewHost(TestView())`
116+
/// `let myView = ViewHost(TestView())`
119117
/// And within the parent view, you should add the view above.
120118
@dynamicMemberLookup
121119
public class _InjectableViewHost<Hosted: InjectViewType>: InjectViewType {
@@ -171,7 +169,7 @@ public class _InjectableViewHost<Hosted: InjectViewType>: InjectViewType {
171169
}
172170
#else
173171

174-
extension Inject {
172+
extension InjectConfiguration {
175173
public static func ViewControllerHost<Hosted: InjectViewControllerType>(_ viewController: Hosted) -> Hosted {
176174
viewController
177175
}

Sources/Inject/Integrations/SwiftUI.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import SwiftUI
66
@available(iOS 13.0, *)
77
public extension SwiftUI.View {
88
func enableInjection() -> some SwiftUI.View {
9-
_ = Inject.load
9+
_ = InjectConfiguration.load
1010

1111
// Use AnyView in case the underlying view structure changes during injection.
1212
// This is only in effect in debug builds.
1313
return AnyView(self)
1414
}
1515

1616
func onInjection(callback: @escaping (Self) -> Void) -> some SwiftUI.View {
17-
onReceive(Inject.observer.objectWillChange, perform: {
17+
onReceive(InjectConfiguration.observer.objectWillChange, perform: {
1818
callback(self)
1919
})
2020
.enableInjection()
@@ -24,9 +24,9 @@ public extension SwiftUI.View {
2424
@available(iOS 13.0, *)
2525
@propertyWrapper @MainActor
2626
public struct ObserveInjection: DynamicProperty {
27-
@ObservedObject private var iO = Inject.observer
27+
@ObservedObject private var iO = InjectConfiguration.observer
2828
public init() {}
29-
public private(set) var wrappedValue: Inject.Type = Inject.self
29+
public private(set) var wrappedValue: InjectConfiguration.Type = InjectConfiguration.self
3030
}
3131

3232
#else
@@ -45,7 +45,7 @@ public extension SwiftUI.View {
4545
@propertyWrapper @MainActor
4646
public struct ObserveInjection: DynamicProperty {
4747
public init() {}
48-
public private(set) var wrappedValue: Inject.Type = Inject.self
48+
public private(set) var wrappedValue: InjectConfiguration.Type = InjectConfiguration.self
4949
}
5050
#endif
5151
#endif

0 commit comments

Comments
 (0)