mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-19 04:39:36 +00:00
* [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses) With permission of the Facebook Open Source team, we are simplifying the Texture license so that clients can rely on the Apache 2 terms that most of Texture is already covered by. This means that code originally forked from AsyncDisplayKit will be re-licensed from "BSD 3-clause + PATENTS v2" to Apache 2 without a PATENTS file. After getting confirmation that the updates to these core files look good, we'll propagate this new license header to all files (in this same PR) and get sign-off from all parties before landing. * [License] Update all Texture source files to be pure Apache 2. * Changelog entry for Apache 2 license update. * Revert "[License] Update all Texture source files to be pure Apache 2." This reverts commit ffa0fbbba9717d871dd16c4b07539f2f8208fc2b. * [License] Update all Texture source files to be pure Apache 2, maintaining copyrights. * [License] Update CONTRIBUTING, README, Podspec & Dangerfile.
73 lines
2.4 KiB
Objective-C
73 lines
2.4 KiB
Objective-C
//
|
|
// ASWeakProxy.m
|
|
// Texture
|
|
//
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
|
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
|
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <AsyncDisplayKit/ASWeakProxy.h>
|
|
#import <AsyncDisplayKit/ASObjectDescriptionHelpers.h>
|
|
#import <AsyncDisplayKit/ASAssert.h>
|
|
|
|
@implementation ASWeakProxy
|
|
|
|
- (instancetype)initWithTarget:(id)target
|
|
{
|
|
if (self) {
|
|
_target = target;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
+ (instancetype)weakProxyWithTarget:(id)target NS_RETURNS_RETAINED
|
|
{
|
|
return [[ASWeakProxy alloc] initWithTarget:target];
|
|
}
|
|
|
|
- (id)forwardingTargetForSelector:(SEL)aSelector
|
|
{
|
|
return _target;
|
|
}
|
|
|
|
- (BOOL)respondsToSelector:(SEL)aSelector
|
|
{
|
|
return [_target respondsToSelector:aSelector];
|
|
}
|
|
|
|
- (BOOL)conformsToProtocol:(Protocol *)aProtocol
|
|
{
|
|
return [_target conformsToProtocol:aProtocol];
|
|
}
|
|
|
|
/// Strangely, this method doesn't get forwarded by ObjC.
|
|
- (BOOL)isKindOfClass:(Class)aClass
|
|
{
|
|
return [_target isKindOfClass:aClass];
|
|
}
|
|
|
|
- (NSString *)description
|
|
{
|
|
return ASObjectDescriptionMake(self, @[@{ @"target": _target ?: (id)kCFNull }]);
|
|
}
|
|
|
|
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
|
|
{
|
|
ASDisplayNodeAssertNil(_target, @"ASWeakProxy got %@ when its target is still alive, which is unexpected.", NSStringFromSelector(_cmd));
|
|
// Unfortunately, in order to get this object to work properly, the use of a method which creates an NSMethodSignature
|
|
// from a C string. -methodSignatureForSelector is called when a compiled definition for the selector cannot be found.
|
|
// This is the place where we have to create our own dud NSMethodSignature. This is necessary because if this method
|
|
// returns nil, a selector not found exception is raised. The string argument to -signatureWithObjCTypes: outlines
|
|
// the return type and arguments to the message. To return a dud NSMethodSignature, pretty much any signature will
|
|
// suffice. Since the -forwardInvocation call will do nothing if the target does not respond to the selector,
|
|
// the dud NSMethodSignature simply gets us around the exception.
|
|
return [NSMethodSignature signatureWithObjCTypes:"@^v^c"];
|
|
}
|
|
- (void)forwardInvocation:(NSInvocation *)invocation
|
|
{
|
|
ASDisplayNodeAssertNil(_target, @"ASWeakProxy got %@ when its target is still alive, which is unexpected.", NSStringFromSelector(_cmd));
|
|
}
|
|
|
|
@end
|