Skip to content

Commit

Permalink
chore: drop namespace and rename symbols, closes #82
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzablocki committed Mar 12, 2024
1 parent bb72d11 commit d394c53
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion InjectHotReload.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "InjectHotReload"
s.version = "1.3.1"
s.version = "1.4.0"
s.summary = "Hot Reloading for Swift applications! "

s.homepage = "https://github.com/krzysztofzablocki/Inject"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ Just 2 steps to enable injection in your `SwiftUI` Views

> *Remember you **don't need** to remove this code when you are done, it's NO-OP in production builds.*
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.
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.

```swift
Inject.animation = .interactiveSpring()
InjectConfiguration.animation = .interactiveSpring()
```

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

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

- `Inject.ViewControllerHost`
- `Inject.ViewHost`
- `ViewControllerHost`
- `ViewHost`

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol InjectListener {
}

/// Public namespace for using Inject API
public enum Inject {
public enum InjectConfiguration {
public static var bundlePath = "/Applications/InjectionIII.app/Contents/Resources/"
@available(iOS 13.0, *)
public static let observer = injectionObserver
Expand All @@ -26,7 +26,7 @@ public extension InjectListener {
/// Ensures injection is enabled
@inlinable @inline(__always)
func enableInjection() {
_ = Inject.load
_ = InjectConfiguration.load
}
}

Expand Down Expand Up @@ -59,10 +59,10 @@ private var loadInjectionImplementation: Void = {

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

if let bundle = Bundle(path: Inject.bundlePath + bundleName) {
if let bundle = Bundle(path: InjectConfiguration.bundlePath + bundleName) {
bundle.load()
} else {
print("⚠️ Inject: InjectionIII bundle not found, verify if it's in \(Inject.bundlePath)")
print("⚠️ Inject: InjectionIII bundle not found, verify if it's in \(InjectConfiguration.bundlePath)")
}
#endif
}()
Expand All @@ -75,7 +75,7 @@ public class InjectionObserver: ObservableObject {
fileprivate init() {
cancellable = NotificationCenter.default.publisher(for: Notification.Name("INJECTION_BUNDLE_NOTIFICATION"))
.sink { [weak self] _ in
if let animation = Inject.animation {
if let animation = InjectConfiguration.animation {
withAnimation(animation) {
self?.injectionNumber += 1
}
Expand Down
16 changes: 7 additions & 9 deletions Sources/Inject/Integrations/Hosts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ public typealias InjectViewType = NSView

#if DEBUG

extension Inject {
public typealias ViewControllerHost = _InjectableViewControllerHost
public typealias ViewHost = _InjectableViewHost
}
public typealias ViewControllerHost = _InjectableViewControllerHost
public typealias ViewHost = _InjectableViewHost

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

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

extension Inject {
extension InjectConfiguration {
public static func ViewControllerHost<Hosted: InjectViewControllerType>(_ viewController: Hosted) -> Hosted {
viewController
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Inject/Integrations/SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import SwiftUI
@available(iOS 13.0, *)
public extension SwiftUI.View {
func enableInjection() -> some SwiftUI.View {
_ = Inject.load
_ = InjectConfiguration.load

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

func onInjection(callback: @escaping (Self) -> Void) -> some SwiftUI.View {
onReceive(Inject.observer.objectWillChange, perform: {
onReceive(InjectConfiguration.observer.objectWillChange, perform: {
callback(self)
})
.enableInjection()
Expand All @@ -24,9 +24,9 @@ public extension SwiftUI.View {
@available(iOS 13.0, *)
@propertyWrapper @MainActor
public struct ObserveInjection: DynamicProperty {
@ObservedObject private var iO = Inject.observer
@ObservedObject private var iO = InjectConfiguration.observer
public init() {}
public private(set) var wrappedValue: Inject.Type = Inject.self
public private(set) var wrappedValue: InjectConfiguration.Type = InjectConfiguration.self
}

#else
Expand All @@ -45,7 +45,7 @@ public extension SwiftUI.View {
@propertyWrapper @MainActor
public struct ObserveInjection: DynamicProperty {
public init() {}
public private(set) var wrappedValue: Inject.Type = Inject.self
public private(set) var wrappedValue: InjectConfiguration.Type = InjectConfiguration.self
}
#endif
#endif

0 comments on commit d394c53

Please sign in to comment.