Skip to content

Commit

Permalink
Dispose UIKit related stuff on the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Dec 12, 2019
1 parent 84eaa8e commit 28373ce
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Bond.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Bond"
s.version = "7.6.1"
s.version = "7.6.2"
s.summary = "A Swift binding framework"

s.description = <<-DESC
Expand All @@ -21,7 +21,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.11"
s.tvos.deployment_target = "9.0"
s.source = { :git => "https://github.com/SwiftBond/Bond.git", :tag => "7.6.1" }
s.source = { :git => "https://github.com/SwiftBond/Bond.git", :tag => "7.6.2" }
s.source_files = "Sources/**/*.{h,m,swift}", "Supporting Files/Bond.h"
s.ios.exclude_files = "Sources/Bond/AppKit"
s.tvos.exclude_files = "Sources/Bond/AppKit"
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "DeclarativeHub/ReactiveKit" "v3.14.2"
github "DeclarativeHub/ReactiveKit" "v3.15.4"
github "tonyarnold/Differ" "1.4.3"
4 changes: 3 additions & 1 deletion Sources/Bond/AppKit/NSGestureRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ extension ReactiveExtensions where Base: NSView {
observer.receive(recog as! T)
}
return BlockDisposable {
target.unregister()
ExecutionContext.immediateOnMain.execute {
target.unregister()
}
}
}
.prefix(untilOutputFrom: base.deallocated)
Expand Down
42 changes: 29 additions & 13 deletions Sources/Bond/ProtocolProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -85,8 +87,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -97,8 +101,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -109,8 +115,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -121,8 +129,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -133,8 +143,10 @@ public class ProtocolProxy: BNDProtocolProxyBase {
}
registerDelegate()
return BlockDisposable { [weak self] in
self?.invokers[selector] = nil
self?.registerDelegate()
ExecutionContext.immediateOnMain.execute {
self?.invokers[selector] = nil
self?.registerDelegate()
}
}
}

Expand All @@ -147,7 +159,11 @@ public class ProtocolProxy: BNDProtocolProxyBase {
let disposable = CompositeDisposable()
disposable += registerInvoker(subject)
disposable += subject.observe(with: observer)
disposable += BlockDisposable { [weak self] in self?.handlers[selector] = nil }
disposable += BlockDisposable { [weak self] in
ExecutionContext.immediateOnMain.execute {
self?.handlers[selector] = nil
}
}
return disposable
}.share(limit: 0)
handlers[selector] = signal
Expand Down
13 changes: 7 additions & 6 deletions Sources/Bond/Shared/NSObject+KVO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ extension ReactiveExtensions where Base: NSObject {
}

return DeinitDisposable(disposable: BlockDisposable {
if #available(iOS 11, *) {} else {
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
base.removeObserver(base, forKeyPath: keyPathString)
ExecutionContext.immediateOnMain.execute {
if #available(iOS 11, *) {} else {
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
base.removeObserver(base, forKeyPath: keyPathString)
}
subscription.invalidate()
disposable.dispose()
}

subscription.invalidate()
disposable.dispose()
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Bond/Shared/NotificationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ extension ReactiveExtensions where Base: NotificationCenter {
observer.receive(notification)
})
return BlockDisposable {
self.base.removeObserver(subscription)
ExecutionContext.immediateOnMain.execute {
self.base.removeObserver(subscription)
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Bond/UIKit/UIControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ extension ReactiveExtensions where Base: UIControl {
observer.receive(())
}
return BlockDisposable {
target.unregister()
ExecutionContext.immediateOnMain.execute {
target.unregister()
}
}
}.prefix(untilOutputFrom: base.deallocated)
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Bond/UIKit/UIGestureRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ extension ReactiveExtensions where Base: UIView {
observer.receive(recog as! T)
}
return BlockDisposable {
target.unregister()
ExecutionContext.immediateOnMain.execute {
target.unregister()
}
}
}.prefix(untilOutputFrom: base.deallocated)
}
Expand Down
2 changes: 1 addition & 1 deletion Supporting Files/Bond-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>7.6.1</string>
<string>7.6.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 28373ce

Please sign in to comment.