Skip to content

Commit

Permalink
Merge pull request krzysztofzablocki#37 from DennisHirschgaenger/main
Browse files Browse the repository at this point in the history
Set deployment target to iOS 11
  • Loading branch information
krzysztofzablocki authored May 13, 2022
2 parents fff24e3 + a16296c commit d229e83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "Inject",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.iOS(.v11),
.tvOS(.v13)
],
products: [
Expand Down
10 changes: 10 additions & 0 deletions Sources/Inject/Inject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public protocol InjectListener {

/// Public namespace for using Inject API
public enum Inject {
@available(iOS 13.0, *)
public static let observer = injectionObserver
public static let load: Void = loadInjectionImplementation
@available(iOS 13.0, *)
public static var animation: SwiftUI.Animation?
}

Expand Down Expand Up @@ -43,6 +45,7 @@ private var loadInjectionImplementation: Void = {
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/" + bundleName)?.load()
}()

@available(iOS 13.0, *)
public class InjectionObserver: ObservableObject {
@Published public private(set) var injectionNumber = 0
private var cancellable: AnyCancellable?
Expand All @@ -61,11 +64,16 @@ public class InjectionObserver: ObservableObject {
}
}

@available(iOS 13.0, *)
private let injectionObserver = InjectionObserver()
@available(iOS 13.0, *)
private var injectionObservationKey = arc4random()

public extension InjectListener where Self: NSObject {
func onInjection(callback: @escaping (Self) -> Void) {
guard #available(iOS 13.0, *) else {
return
}
let observation = injectionObserver.objectWillChange.sink(receiveValue: { [weak self] in
guard let self = self else { return }
callback(self)
Expand All @@ -76,7 +84,9 @@ public extension InjectListener where Self: NSObject {
}

#else
@available(iOS 13.0, *)
public class InjectionObserver: ObservableObject {}
@available(iOS 13.0, *)
private let injectionObserver = InjectionObserver()
private var loadInjectionImplementation: Void = {}()

Expand Down
4 changes: 4 additions & 0 deletions Sources/Inject/Integrations/SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import SwiftUI

#if DEBUG
@available(iOS 13.0, *)
public extension SwiftUI.View {
func enableInjection() -> some SwiftUI.View {
_ = Inject.load
Expand All @@ -19,6 +20,7 @@ public extension SwiftUI.View {
}
}

@available(iOS 13.0, *)
@propertyWrapper
public struct ObserveInjection: DynamicProperty {
@ObservedObject private var iO = Inject.observer
Expand All @@ -27,6 +29,7 @@ public struct ObserveInjection: DynamicProperty {
}

#else
@available(iOS 13.0, *)
public extension SwiftUI.View {
@inlinable @inline(__always)
func enableInjection() -> Self { self }
Expand All @@ -37,6 +40,7 @@ public extension SwiftUI.View {
}
}

@available(iOS 13.0, *)
@propertyWrapper
public struct ObserveInjection {
public init() {}
Expand Down

0 comments on commit d229e83

Please sign in to comment.