diff --git a/Rx.xcodeproj/project.pbxproj b/Rx.xcodeproj/project.pbxproj index 1223dd71e..74fcc7d8d 100644 --- a/Rx.xcodeproj/project.pbxproj +++ b/Rx.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -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 */; }; @@ -971,7 +970,6 @@ 4C5213A9225D41E60079FC77 /* CompactMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompactMap.swift; sourceTree = ""; }; 4C5213AB225E20350079FC77 /* Observable+CompactMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Observable+CompactMapTests.swift"; sourceTree = ""; }; 4C8DE0E120D54545003E2D8A /* DisposeBagTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisposeBagTest.swift; sourceTree = ""; }; - 5039386028CB6479003A0ACC /* RxDelegateProxyCrashFix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxDelegateProxyCrashFix.swift; sourceTree = ""; }; 504540C824196D960098665F /* WKWebView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WKWebView+Rx.swift"; sourceTree = ""; }; 504540CA24196EB10098665F /* WKWebView+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WKWebView+RxTests.swift"; sourceTree = ""; }; 504540CD2419701D0098665F /* RxWKNavigationDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxWKNavigationDelegateProxy.swift; sourceTree = ""; }; @@ -2317,7 +2315,6 @@ D9080ACD1EA05A16002B433B /* RxNavigationControllerDelegateProxy.swift */, 504540CD2419701D0098665F /* RxWKNavigationDelegateProxy.swift */, A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */, - 5039386028CB6479003A0ACC /* RxDelegateProxyCrashFix.swift */, ); path = Proxies; sourceTree = ""; @@ -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 */, ); diff --git a/RxCocoa/Runtime/_RXDelegateProxy.m b/RxCocoa/Runtime/_RXDelegateProxy.m index 36338a575..872824443 100644 --- a/RxCocoa/Runtime/_RXDelegateProxy.m +++ b/RxCocoa/Runtime/_RXDelegateProxy.m @@ -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; diff --git a/RxCocoa/iOS/Proxies/RxDelegateProxyCrashFix.swift b/RxCocoa/iOS/Proxies/RxDelegateProxyCrashFix.swift deleted file mode 100644 index 04f7eb184..000000000 --- a/RxCocoa/iOS/Proxies/RxDelegateProxyCrashFix.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// RxDelegateProxyCrashFix.swift -// RxCocoa -// -// Created by SlashDevSlashGnoll (SlashDevSlashGnoll@users.noreply.github.com) on 9/9/22. -// Copyright © 2022 Krunoslav Zaher. All rights reserved. -// - -#if os(iOS) || os(tvOS) -import Foundation - -// This extension exists solely to get around a crash found on iOS 15.4+ where a `text` -// method invocation is being sent to the RxCollectionViewDelegateProxy which doesn't implement it. -// This is tracked at this bug: https://github.com/ReactiveX/RxSwift/issues/2428 This can be -// removed if/when the actual source of the problem is found -@objc extension RxCollectionViewDelegateProxy { - var text: String { - return String() - } -} - -// This extension exists solely to get around a crash found on iOS 15.4+ where a `text` -// method invocation is being sent to the RxTableViewDelegateProxy which doesn't implement it. -// This is tracked at this bug: https://github.com/ReactiveX/RxSwift/issues/2428 This can be -//removed if/when the actual source of the problem is found -@objc extension RxTableViewDelegateProxy { - var text: String { - return String() - } -} -#endif diff --git a/Tests/RxCocoaTests/DelegateProxyTest.swift b/Tests/RxCocoaTests/DelegateProxyTest.swift index 4a3606963..0d67b25a6 100644 --- a/Tests/RxCocoaTests/DelegateProxyTest.swift +++ b/Tests/RxCocoaTests/DelegateProxyTest.swift @@ -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") + } + } +}