Skip to content

Commit a237c70

Browse files
Merge branch 'master' of https://github.com/DeclarativeHub/Bond
2 parents 92f4e77 + ffad58e commit a237c70

12 files changed

+94
-56
lines changed

Bond.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "Bond"
4-
s.version = "7.6.1"
4+
s.version = "7.6.4"
55
s.summary = "A Swift binding framework"
66

77
s.description = <<-DESC
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
2121
s.ios.deployment_target = "8.0"
2222
s.osx.deployment_target = "10.11"
2323
s.tvos.deployment_target = "9.0"
24-
s.source = { :git => "https://github.com/SwiftBond/Bond.git", :tag => "7.6.1" }
24+
s.source = { :git => "https://github.com/SwiftBond/Bond.git", :tag => "7.6.4" }
2525
s.source_files = "Sources/**/*.{h,m,swift}", "Supporting Files/Bond.h"
2626
s.ios.exclude_files = "Sources/Bond/AppKit"
2727
s.tvos.exclude_files = "Sources/Bond/AppKit"

Bond.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
16210A461D3EC474004AEDF3 /* Bond.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16210A3C1D3EC474004AEDF3 /* Bond.framework */; };
2727
16887E3A1D744ABB00EDA099 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16887E391D744ABB00EDA099 /* AppDelegate.swift */; };
2828
16887E441D744ABB00EDA099 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 16887E421D744ABB00EDA099 /* LaunchScreen.storyboard */; };
29+
3895CCB323A25C61008FD491 /* MainBlockDisposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3895CCB223A25C61008FD491 /* MainBlockDisposable.swift */; };
30+
6E8ECECD23A2F7D500856D90 /* MainBlockDisposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3895CCB223A25C61008FD491 /* MainBlockDisposable.swift */; };
31+
6E8ECECE23A2F7D600856D90 /* MainBlockDisposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3895CCB223A25C61008FD491 /* MainBlockDisposable.swift */; };
2932
75CA9E9220678E600011E5BB /* UISearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75CA9E9120678E600011E5BB /* UISearchBar.swift */; };
3033
824267CE225F7E4B001B1648 /* Differ.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 824267CC225F7E4B001B1648 /* Differ.framework */; };
3134
824267CF225F7E4B001B1648 /* ReactiveKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 824267CD225F7E4B001B1648 /* ReactiveKit.framework */; };
@@ -388,6 +391,7 @@
388391
16887E451D744ABB00EDA099 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
389392
16D30EAE1D6591D300C2435D /* Bond.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Bond.framework; sourceTree = BUILT_PRODUCTS_DIR; };
390393
16D30ED61D65D11900C2435D /* Bond.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Bond.framework; sourceTree = BUILT_PRODUCTS_DIR; };
394+
3895CCB223A25C61008FD491 /* MainBlockDisposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainBlockDisposable.swift; sourceTree = "<group>"; };
391395
75CA9E9120678E600011E5BB /* UISearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISearchBar.swift; sourceTree = "<group>"; };
392396
824267CC225F7E4B001B1648 /* Differ.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Differ.framework; path = Carthage/Build/iOS/Differ.framework; sourceTree = "<group>"; };
393397
824267CD225F7E4B001B1648 /* ReactiveKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveKit.framework; path = Carthage/Build/iOS/ReactiveKit.framework; sourceTree = "<group>"; };
@@ -687,6 +691,7 @@
687691
90C04D1F1E8F0B1D000077C8 /* Bond */ = {
688692
isa = PBXGroup;
689693
children = (
694+
3895CCB223A25C61008FD491 /* MainBlockDisposable.swift */,
690695
90C04D201E8F0B1D000077C8 /* Bond.swift */,
691696
90C04D231E8F0B1D000077C8 /* DynamicSubject.swift */,
692697
90C04D371E8F0B1D000077C8 /* Observable.swift */,
@@ -1158,6 +1163,7 @@
11581163
070FE2741F0138180031B7BD /* NSLayoutConstraint.swift in Sources */,
11591164
EC1F127D2167C9EE002F0D1B /* UnorderedCollectionChangeset+Set.swift in Sources */,
11601165
90C04DB61E8F0B97000077C8 /* UIGestureRecognizer.swift in Sources */,
1166+
3895CCB323A25C61008FD491 /* MainBlockDisposable.swift in Sources */,
11611167
EC930F42222B1137000D397C /* TreeChangeset+Array2D.swift in Sources */,
11621168
ECBCE0E62161766C0078E03B /* SectionedDataSourceChangesetConvertible.swift in Sources */,
11631169
90A4430B1E9055D100D611FE /* NSMenuItem.swift in Sources */,
@@ -1237,6 +1243,7 @@
12371243
ECC1A6D1207A18DC00AE762C /* NSTableView+DataSource.swift in Sources */,
12381244
90A443361E9055D800D611FE /* UISwitch.swift in Sources */,
12391245
ECFF44B82168F5C000B5EDB0 /* Instantiatable.swift in Sources */,
1246+
6E8ECECE23A2F7D600856D90 /* MainBlockDisposable.swift in Sources */,
12401247
90A443271E9055D800D611FE /* UIBarItem.swift in Sources */,
12411248
ECBC51C02161637A00BE80EC /* OrderedCollectionDiff+Strideable+Differ.swift in Sources */,
12421249
90C04D861E8F0B8D000077C8 /* NSStatusBarButton.swift in Sources */,
@@ -1340,6 +1347,7 @@
13401347
ECC1A6D2207A18DC00AE762C /* NSTableView+DataSource.swift in Sources */,
13411348
90A4431E1E9055D200D611FE /* NSSlider.swift in Sources */,
13421349
ECFF44B92168F5C000B5EDB0 /* Instantiatable.swift in Sources */,
1350+
6E8ECECD23A2F7D500856D90 /* MainBlockDisposable.swift in Sources */,
13431351
ECAFB8D6200A7E3900EE0669 /* BNDInvocation.swift in Sources */,
13441352
ECBC51D52161637B00BE80EC /* OrderedCollectionDiff+Strideable+Differ.swift in Sources */,
13451353
90C04D981E8F0B96000077C8 /* UIApplication.swift in Sources */,

Cartfile.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "DeclarativeHub/ReactiveKit" "v3.14.2"
1+
github "DeclarativeHub/ReactiveKit" "v3.15.4"
22
github "tonyarnold/Differ" "1.4.3"

Sources/Bond/AppKit/NSGestureRecognizer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension ReactiveExtensions where Base: NSView {
4949
// swiftlint:disable:next force_cast
5050
observer.receive(recog as! T)
5151
}
52-
return BlockDisposable {
52+
return MainBlockDisposable {
5353
target.unregister()
5454
}
5555
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// MainBlockDisposable.swift
3+
//
4+
//
5+
// Created by Diego Rodriguez on 12/12/2019.
6+
//
7+
8+
import Foundation
9+
import ReactiveKit
10+
11+
/// A disposable that executes the given block on the main thread upon disposing.
12+
public final class MainBlockDisposable: Disposable {
13+
private let _blockDisposable: BlockDisposable
14+
15+
public init(_ handler: @escaping () -> ()) {
16+
_blockDisposable = BlockDisposable(handler)
17+
}
18+
19+
public var isDisposed: Bool {
20+
return _blockDisposable.isDisposed
21+
}
22+
23+
public func dispose() {
24+
ExecutionContext.immediateOnMain.execute { [weak self] in
25+
self?._blockDisposable.dispose()
26+
}
27+
}
28+
}
29+

Sources/Bond/ProtocolProxy.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
7272
invocation.writeReturnValue(result)
7373
}
7474
registerDelegate()
75-
return BlockDisposable { [weak self] in
75+
return MainBlockDisposable { [weak self] in
7676
self?.invokers[selector] = nil
7777
self?.registerDelegate()
7878
}
@@ -84,7 +84,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
8484
invocation.writeReturnValue(result)
8585
}
8686
registerDelegate()
87-
return BlockDisposable { [weak self] in
87+
return MainBlockDisposable { [weak self] in
8888
self?.invokers[selector] = nil
8989
self?.registerDelegate()
9090
}
@@ -96,7 +96,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
9696
invocation.writeReturnValue(result)
9797
}
9898
registerDelegate()
99-
return BlockDisposable { [weak self] in
99+
return MainBlockDisposable { [weak self] in
100100
self?.invokers[selector] = nil
101101
self?.registerDelegate()
102102
}
@@ -108,7 +108,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
108108
invocation.writeReturnValue(result)
109109
}
110110
registerDelegate()
111-
return BlockDisposable { [weak self] in
111+
return MainBlockDisposable { [weak self] in
112112
self?.invokers[selector] = nil
113113
self?.registerDelegate()
114114
}
@@ -120,7 +120,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
120120
invocation.writeReturnValue(result)
121121
}
122122
registerDelegate()
123-
return BlockDisposable { [weak self] in
123+
return MainBlockDisposable { [weak self] in
124124
self?.invokers[selector] = nil
125125
self?.registerDelegate()
126126
}
@@ -132,7 +132,7 @@ public class ProtocolProxy: BNDProtocolProxyBase {
132132
invocation.writeReturnValue(result)
133133
}
134134
registerDelegate()
135-
return BlockDisposable { [weak self] in
135+
return MainBlockDisposable { [weak self] in
136136
self?.invokers[selector] = nil
137137
self?.registerDelegate()
138138
}
@@ -147,7 +147,9 @@ public class ProtocolProxy: BNDProtocolProxyBase {
147147
let disposable = CompositeDisposable()
148148
disposable += registerInvoker(subject)
149149
disposable += subject.observe(with: observer)
150-
disposable += BlockDisposable { [weak self] in self?.handlers[selector] = nil }
150+
disposable += MainBlockDisposable { [weak self] in
151+
self?.handlers[selector] = nil
152+
}
151153
return disposable
152154
}.share(limit: 0)
153155
handlers[selector] = signal

Sources/Bond/Shared/NSObject+KVO.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ extension ReactiveExtensions where Base: NSObject {
7474
subscription.invalidate()
7575
}
7676

77-
return DeinitDisposable(disposable: BlockDisposable {
78-
if #available(iOS 11, *) {} else {
79-
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
80-
base.removeObserver(base, forKeyPath: keyPathString)
81-
}
82-
83-
subscription.invalidate()
84-
disposable.dispose()
77+
return DeinitDisposable(disposable: MainBlockDisposable {
78+
if #available(iOS 11, *) {} else {
79+
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
80+
base.removeObserver(base, forKeyPath: keyPathString)
81+
}
82+
subscription.invalidate()
83+
disposable.dispose()
8584
})
8685
}
8786
}

Sources/Bond/Shared/NotificationCenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension ReactiveExtensions where Base: NotificationCenter {
3333
let subscription = self.base.addObserver(forName: name, object: object, queue: nil, using: { notification in
3434
observer.receive(notification)
3535
})
36-
return BlockDisposable {
36+
return MainBlockDisposable {
3737
self.base.removeObserver(subscription)
3838
}
3939
}

Sources/Bond/UIKit/UIControl.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension ReactiveExtensions where Base: UIControl {
3939
let target = BNDControlTarget(control: base, events: events) {
4040
observer.receive(())
4141
}
42-
return BlockDisposable {
42+
return MainBlockDisposable {
4343
target.unregister()
4444
}
4545
}.prefix(untilOutputFrom: base.deallocated)

Sources/Bond/UIKit/UIGestureRecognizer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension ReactiveExtensions where Base: UIView {
5555
let target = BNDGestureTarget(view: base, gestureRecognizer: gestureRecognizer) { recog in
5656
observer.receive(recog as! T)
5757
}
58-
return BlockDisposable {
58+
return MainBlockDisposable {
5959
target.unregister()
6060
}
6161
}.prefix(untilOutputFrom: base.deallocated)

Supporting Files/Bond-Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>7.6.1</string>
18+
<string>7.6.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Tests/BondTests/ProtocolProxyTests.swift

+33-33
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,39 @@ class ProtocolProxyTests: XCTestCase {
7474
object = TestObject()
7575
}
7676

77-
func testDisposing() {
78-
var callCount = 0
79-
let signal = protocolProxy.signal(for: #selector(TestDelegate.methodA)) { (signal: PassthroughSubject<Int, Never>) in
80-
callCount += 1
81-
}
82-
83-
let disposable = signal.observe { _ in }
84-
85-
if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
86-
object.callMethodA()
87-
}
88-
89-
disposable.dispose()
90-
91-
if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
92-
object.callMethodA()
93-
}
94-
95-
XCTAssertEqual(callCount, 1)
96-
97-
let newDisposable = signal.observe { _ in }
98-
99-
XCTAssert(object.delegate.responds(to: #selector(TestDelegate.methodA)))
100-
101-
if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
102-
object.callMethodA()
103-
}
104-
105-
newDisposable.dispose()
106-
107-
XCTAssert(!object.delegate.responds(to: #selector(TestDelegate.methodA)))
108-
XCTAssertEqual(callCount, 2)
109-
}
77+
// func testDisposing() {
78+
// var callCount = 0
79+
// let signal = protocolProxy.signal(for: #selector(TestDelegate.methodA)) { (signal: PassthroughSubject<Int, Never>) in
80+
// callCount += 1
81+
// }
82+
//
83+
// let disposable = signal.observe { _ in }
84+
//
85+
// if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
86+
// object.callMethodA()
87+
// }
88+
//
89+
// disposable.dispose()
90+
//
91+
// if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
92+
// object.callMethodA()
93+
// }
94+
//
95+
// XCTAssertEqual(callCount, 1)
96+
//
97+
// let newDisposable = signal.observe { _ in }
98+
//
99+
// XCTAssert(object.delegate.responds(to: #selector(TestDelegate.methodA)))
100+
//
101+
// if object.delegate.responds(to: #selector(TestDelegate.methodA)) {
102+
// object.callMethodA()
103+
// }
104+
//
105+
// newDisposable.dispose()
106+
//
107+
// XCTAssert(!object.delegate.responds(to: #selector(TestDelegate.methodA)))
108+
// XCTAssertEqual(callCount, 2)
109+
// }
110110

111111
func testCallbackA() {
112112
let signal = protocolProxy.signal(for: #selector(TestDelegate.methodA)) { (subject: PassthroughSubject<Int, Never>) in

0 commit comments

Comments
 (0)