Skip to content

Commit

Permalink
Merge pull request #52 from zenangst/improve/not-loading-injection-in…
Browse files Browse the repository at this point in the history
…-release

Add extra constraint to not load injection unless the main bundle is in derived data
  • Loading branch information
zenangst committed Nov 15, 2018
2 parents 42e16c2 + 7b3bbbf commit b529121
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Source/Shared/Injection.swift
Expand Up @@ -86,6 +86,10 @@ public class Injection {
return true
}

if !Bundle.main.bundlePath.lowercased().contains("products/debug") {
return true
}

// Search for injection in the loaded bundles.
var result: Bool = false
for bundle in Bundle.allBundles {
Expand Down Expand Up @@ -116,6 +120,7 @@ public class Injection {
@discardableResult public static func load(then handler: (() -> Void)? = nil,
swizzling: Bool = true,
animations: Bool = true) -> Injection.Type {
defer { handler?() }
guard !Injection.isLoaded else { return self }

#if targetEnvironment(simulator) || os(macOS)
Expand All @@ -131,7 +136,6 @@ public class Injection {
swizzleCollectionViews = swizzling
swizzleCollectionViewLayouts = swizzling
self.animations = animations
handler?()
return self
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/iOS+tvOS/UIApplicationDelegateTests.swift
Expand Up @@ -21,6 +21,6 @@ class UIApplicationDelegateTests: XCTestCase {
Injection.load(then: applicationDelegate.loadInitialState)
applicationDelegate.addInjection(with: #selector(ApplicationDelegateMock.injected(_:)))
utilities.triggerInjection()
XCTAssertEqual(applicationDelegate.timesInvoked, 1)
XCTAssertEqual(applicationDelegate.timesInvoked, 2)
}
}
2 changes: 1 addition & 1 deletion Tests/macOS/NSApplicationDelegateTests.swift
Expand Up @@ -21,6 +21,6 @@ class NSApplicationDelegateTests: XCTestCase {
Injection.load(then: { applicationDelegate.loadInitialState() })
applicationDelegate.addInjection(with: #selector(ApplicationDelegateMock.injected(_:)))
utilities.triggerInjection()
XCTAssertEqual(applicationDelegate.timesInvoked, 1)
XCTAssertEqual(applicationDelegate.timesInvoked, 2)
}
}
2 changes: 1 addition & 1 deletion Vaccine.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Vaccine"
s.summary = "Make your apps immune to recompile-disease."
s.version = "0.14.0"
s.version = "0.14.1"
s.homepage = "https://github.com/zenangst/Vaccine"
s.license = 'MIT'
s.author = { "Christoffer Winterkvist" => "christoffer@winterkvist.com" }
Expand Down

0 comments on commit b529121

Please sign in to comment.