Skip to content

Commit 0102e21

Browse files
Andrey Mishaninfacebook-github-bot
authored andcommitted
Removed NSObject (CKComponentDelegateProxy)
Summary: Remove ObjC categories so we can strip dead code Reviewed By: cuva Differential Revision: D14683303 fbshipit-source-id: 022ef7de7e8be70559221acbf3c81cdf7ad0c6a3
1 parent e8d3fff commit 0102e21

4 files changed

Lines changed: 18 additions & 28 deletions

File tree

ComponentKit/Utilities/CKComponentDelegateAttribute.mm

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#import "CKComponent+UIView.h"
1818
#import "CKComponentSubclass.h"
1919

20-
@interface UIView (CKDelegateProxy)
21-
22-
@property (nonatomic, strong, setter=ck_setDelegateProxy:) CKComponentDelegateForwarder *ck_delegateProxy;
23-
24-
@end
25-
2620
CKComponentViewAttributeValue CKComponentDelegateAttribute(SEL selector,
2721
CKComponentForwardedSelectors selectors) noexcept
2822
{
@@ -43,12 +37,12 @@ CKComponentViewAttributeValue CKComponentDelegateAttribute(SEL selector,
4337

4438
// Create a proxy for this set of selectors
4539

46-
CKCAssertNil(view.ck_delegateProxy,
47-
@"Unsupported: registered two delegate proxies for the same view: %@ %@", view, view.ck_delegateProxy);
40+
CKCAssertNil(CKDelegateProxyForObject(view),
41+
@"Unsupported: registered two delegate proxies for the same view: %@ %@", view, CKDelegateProxyForObject(view));
4842

4943
CKComponentDelegateForwarder *proxy = [CKComponentDelegateForwarder newWithSelectors:selectors];
5044
proxy.view = view;
51-
view.ck_delegateProxy = proxy;
45+
CKSetDelegateProxyForObject(view, proxy);
5246

5347
#pragma clang diagnostic push
5448
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
@@ -59,9 +53,9 @@ CKComponentViewAttributeValue CKComponentDelegateAttribute(SEL selector,
5953
^(UIView *view, id value){
6054

6155
// When unapplied, remove association with the view
62-
CKComponentDelegateForwarder *proxy = view.ck_delegateProxy;
56+
CKComponentDelegateForwarder *proxy = CKDelegateProxyForObject(view);
6357
proxy.view = nil;
64-
view.ck_delegateProxy = nil;
58+
CKSetDelegateProxyForObject(view, nil);
6559

6660
#pragma clang diagnostic push
6761
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

ComponentKit/Utilities/CKComponentDelegateForwarder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ std::string CKIdentifierFromDelegateForwarderSelectors(const CKComponentForwarde
2929
/**
3030
This initializer will make an object that forwards calls to the given selectors on to the component, and its nextResponder, etc.
3131
*/
32-
+ (instancetype)newWithSelectors:(CKComponentForwardedSelectors)selectors;
32+
+ (instancetype _Nullable)newWithSelectors:(CKComponentForwardedSelectors)selectors;
3333

3434
/**
3535
The view is used to find out where to start looking in the component responder chain.
3636
3737
The forwarder will call [CKMountedComponentForView(view) targetForAction: withSender:] to proxy to the responder chain, so this needs to be accurate when you mount/unmount.
3838
*/
39-
@property (nonatomic, weak) UIView *view;
39+
@property (nonatomic, weak) UIView * _Nullable view;
4040

4141
@end
4242

43+
NS_ASSUME_NONNULL_BEGIN
4344

44-
@interface NSObject (CKComponentDelegateProxy)
45+
auto CKDelegateProxyForObject(NSObject *obj) -> CKComponentDelegateForwarder *_Nullable;
46+
auto CKSetDelegateProxyForObject(NSObject *obj, CKComponentDelegateForwarder *_Nullable delegateProxy) -> void;
4547

46-
@property (nonatomic, strong, setter=ck_setDelegateProxy:) CKComponentDelegateForwarder *ck_delegateProxy;
47-
48-
@end
48+
NS_ASSUME_NONNULL_END

ComponentKit/Utilities/CKComponentDelegateForwarder.mm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,14 @@ static BOOL selectorInList(SEL selector, const CKComponentForwardedSelectors &se
113113

114114
@end
115115

116-
@implementation NSObject (CKComponentDelegateForwarder)
117-
118116
static const char kCKComponentDelegateProxyKey = ' ';
119117

120-
- (CKComponentDelegateForwarder *)ck_delegateProxy
118+
auto CKDelegateProxyForObject(NSObject *obj) -> CKComponentDelegateForwarder *
121119
{
122-
return objc_getAssociatedObject(self, &kCKComponentDelegateProxyKey);
120+
return objc_getAssociatedObject(obj, &kCKComponentDelegateProxyKey);
123121
}
124122

125-
- (void)ck_setDelegateProxy:(CKComponentDelegateForwarder *)delegateProxy
123+
auto CKSetDelegateProxyForObject(NSObject *obj, CKComponentDelegateForwarder *delegateProxy) -> void
126124
{
127-
objc_setAssociatedObject(self, &kCKComponentDelegateProxyKey, delegateProxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
125+
objc_setAssociatedObject(obj, &kCKComponentDelegateProxyKey, delegateProxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
128126
}
129-
130-
@end

ComponentKit/Utilities/CKComponentGestureActions.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ CKComponentViewAttributeValue CKComponentGestureAttribute(Class gestureRecognize
141141
proxy.view = view;
142142
gestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)proxy;
143143
// This will retain it
144-
gestureRecognizer.ck_delegateProxy = proxy;
144+
CKSetDelegateProxyForObject(gestureRecognizer, proxy);
145145
}
146146
[view addGestureRecognizer:gestureRecognizer];
147147
},
@@ -156,10 +156,10 @@ CKComponentViewAttributeValue CKComponentGestureAttribute(Class gestureRecognize
156156

157157
// Tear down delegate proxying if applicable
158158
if (delegateSelectors.size() > 0) {
159-
CKComponentDelegateForwarder *proxy = recognizer.ck_delegateProxy;
159+
CKComponentDelegateForwarder *proxy = CKDelegateProxyForObject(recognizer);
160160
proxy.view = nil;
161161
recognizer.delegate = nil;
162-
recognizer.ck_delegateProxy = nil;
162+
CKSetDelegateProxyForObject(recognizer, nil);
163163
}
164164
reusePool->recycle(recognizer);
165165
}

0 commit comments

Comments
 (0)