Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DelegateProxy crash by implementing methodSignatureForSelector #2546

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Rx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -38,7 +38,6 @@
4C8DE0E220D54545003E2D8A /* DisposeBagTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8DE0E120D54545003E2D8A /* DisposeBagTest.swift */; };
4C8DE0E320D54545003E2D8A /* DisposeBagTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8DE0E120D54545003E2D8A /* DisposeBagTest.swift */; };
4C8DE0E420D54545003E2D8A /* DisposeBagTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8DE0E120D54545003E2D8A /* DisposeBagTest.swift */; };
5039386128CB6479003A0ACC /* RxDelegateProxyCrashFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5039386028CB6479003A0ACC /* RxDelegateProxyCrashFix.swift */; };
504540C924196D960098665F /* WKWebView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504540C824196D960098665F /* WKWebView+Rx.swift */; };
504540CB24196EB10098665F /* WKWebView+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504540CA24196EB10098665F /* WKWebView+RxTests.swift */; };
504540CC24196EB10098665F /* WKWebView+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504540CA24196EB10098665F /* WKWebView+RxTests.swift */; };
Expand Down Expand Up @@ -971,7 +970,6 @@
4C5213A9225D41E60079FC77 /* CompactMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompactMap.swift; sourceTree = "<group>"; };
4C5213AB225E20350079FC77 /* Observable+CompactMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Observable+CompactMapTests.swift"; sourceTree = "<group>"; };
4C8DE0E120D54545003E2D8A /* DisposeBagTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisposeBagTest.swift; sourceTree = "<group>"; };
5039386028CB6479003A0ACC /* RxDelegateProxyCrashFix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxDelegateProxyCrashFix.swift; sourceTree = "<group>"; };
504540C824196D960098665F /* WKWebView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WKWebView+Rx.swift"; sourceTree = "<group>"; };
504540CA24196EB10098665F /* WKWebView+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WKWebView+RxTests.swift"; sourceTree = "<group>"; };
504540CD2419701D0098665F /* RxWKNavigationDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxWKNavigationDelegateProxy.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2317,7 +2315,6 @@
D9080ACD1EA05A16002B433B /* RxNavigationControllerDelegateProxy.swift */,
504540CD2419701D0098665F /* RxWKNavigationDelegateProxy.swift */,
A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */,
5039386028CB6479003A0ACC /* RxDelegateProxyCrashFix.swift */,
);
path = Proxies;
sourceTree = "<group>";
Expand Down Expand Up @@ -3119,7 +3116,6 @@
504540C924196D960098665F /* WKWebView+Rx.swift in Sources */,
DB08833726FB0637005805BE /* SharedSequence+Concurrency.swift in Sources */,
C89AB1731DAAC1680065FBE6 /* ControlTarget.swift in Sources */,
5039386128CB6479003A0ACC /* RxDelegateProxyCrashFix.swift in Sources */,
C882541B1B8A752B00B02D69 /* RxTableViewDataSourceType.swift in Sources */,
B5624794203532F500D3EE75 /* RxTableViewDataSourcePrefetchingProxy.swift in Sources */,
);
Expand Down
8 changes: 8 additions & 0 deletions RxCocoa/Runtime/_RXDelegateProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ -(BOOL)voidDelegateMethodsContain:(SEL)selector {
}
}

-(NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
NSMethodSignature *signature = [super methodSignatureForSelector:selector];
if (!signature) {
signature = [self._forwardToDelegate methodSignatureForSelector:selector];
}
return signature;
}

-(void)forwardInvocation:(NSInvocation *)anInvocation {
BOOL isVoid = RX_is_method_signature_void(anInvocation.methodSignature);
NSArray *arguments = nil;
Expand Down
31 changes: 0 additions & 31 deletions RxCocoa/iOS/Proxies/RxDelegateProxyCrashFix.swift

This file was deleted.

25 changes: 25 additions & 0 deletions Tests/RxCocoaTests/DelegateProxyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -774,3 +774,28 @@ extension MockTestDelegateProtocol
{
}
#endif

@objc class MockDelegate: NSObject, UICollectionViewDelegate {
@objc var demoText: String {
return ""
}
}

extension DelegateProxyTest {
/// Test for verifying the fix for the crash reported in https://github.com/ReactiveX/RxSwift/issues/2428
func testDelegateProxyNotCrashing() {
let collection = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
let mockDelegate = MockDelegate()
collection.delegate = mockDelegate
collection.rx.contentOffset.subscribe().disposed(by: DisposeBag())

let selector = #selector(getter: MockDelegate.demoText)
if ((collection.delegate?.responds(to: selector)) != nil) {
let performResult = collection.delegate?.perform(selector)?.takeRetainedValue()
let text = performResult as? String ?? "unknown-result"
XCTAssertEqual(text, "")
} else {
XCTFail("RxDelegateProxyCrashFix does not work")
}
}
}