You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

316 lines
13 KiB

/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2020 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// NSObject+QMUI.h
// qmui
//
// Created by QMUI Team on 2016/11/1.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSObject (QMUI)
/**
@param selector
@param superclass superclass
@return YES NO NO
*/
- (BOOL)qmui_hasOverrideMethod:(SEL)selector ofSuperclass:(Class)superclass;
/**
@param selector
@param superclass superclass
@return YES NO NO
*/
+ (BOOL)qmui_hasOverrideMethod:(SEL)selector forClass:(Class)aClass ofSuperclass:(Class)superclass;
/**
super
@param aSelector
@return
@link http://stackoverflow.com/questions/14635024/using-objc-msgsendsuper-to-invoke-a-class-method @/link
*/
- (nullable id)qmui_performSelectorToSuperclass:(SEL)aSelector;
/**
super
@param aSelector
@param object
@return
@link http://stackoverflow.com/questions/14635024/using-objc-msgsendsuper-to-invoke-a-class-method @/link
*/
- (nullable id)qmui_performSelectorToSuperclass:(SEL)aSelector withObject:(nullable id)object;
/**
* selector使 performSelector:
* @param selector
* @param returnValue selector &result
*
* @code
* CGFloat alpha;
* [view qmui_performSelector:@selector(alpha) withPrimitiveReturnValue:&alpha];
* @endcode
*/
- (void)qmui_performSelector:(SEL)selector withPrimitiveReturnValue:(nullable void *)returnValue;
/**
* selector void
* @param selector
* @param firstArgument
* @return void nil
*
* @code
* id target = xxx;
* SEL action = xxx;
* UIControlEvents events = xxx;
* [control qmui_performSelector:@selector(addTarget:action:forControlEvents:) withArguments:&target, &action, &events, nil];
* @endcode
*/
- (nullable id)qmui_performSelector:(SEL)selector withArguments:(nullable void *)firstArgument, ...;
/**
* selector
*
* @param selector
* @param returnValue selector
* @param firstArgument
*
* @code
* CGPoint point = xxx;
* UIEvent *event = xxx;
* BOOL isInside;
* [view qmui_performSelector:@selector(pointInside:withEvent:) withPrimitiveReturnValue:&isInside arguments:&point, &event, nil];
* @endcode
*/
- (void)qmui_performSelector:(SEL)selector withPrimitiveReturnValue:(nullable void *)returnValue arguments:(nullable void *)firstArgument, ...;
/**
使 block class _xxx property _property superclasses
@param block block
*/
- (void)qmui_enumrateIvarsUsingBlock:(void (^)(Ivar ivar, NSString *ivarDescription))block;
/**
使 block class _xxx property _property
@param aClass class
@param includingInherited ivars
@param block block
*/
+ (void)qmui_enumrateIvarsOfClass:(Class)aClass includingInherited:(BOOL)includingInherited usingBlock:(void (^)(Ivar ivar, NSString *ivarDescription))block;
/**
使 block class superclasses property
@param block block property QMUIPropertyDescriptor
*/
- (void)qmui_enumratePropertiesUsingBlock:(void (^)(objc_property_t property, NSString *propertyName))block;
/**
使 block class
@param aClass class
@param includingInherited property
@param block block property QMUIPropertyDescriptor
@see https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW1
*/
+ (void)qmui_enumratePropertiesOfClass:(Class)aClass includingInherited:(BOOL)includingInherited usingBlock:(void (^)(objc_property_t property, NSString *propertyName))block;
/**
使 block superclasses method
*/
- (void)qmui_enumrateInstanceMethodsUsingBlock:(void (^)(Method method, SEL selector))block;
/**
使 block
@param aClass class
@param includingInherited method
@param block block
*/
+ (void)qmui_enumrateInstanceMethodsOfClass:(Class)aClass includingInherited:(BOOL)includingInherited usingBlock:(void (^)(Method method, SEL selector))block;
/**
protocol
@param protocol protocol \@protocol(xxx)
@param block block
*/
+ (void)qmui_enumerateProtocolMethods:(Protocol *)protocol usingBlock:(void (^)(SEL selector))block;
@end
@interface NSObject (QMUI_KeyValueCoding)
/**
iOS 13 KVC 访 API access prohibited valueForKey: 使
iOS 12 valueForKey:
@note QMUI 2 access prohibited
1. IgnoreKVCAccessProhibited YES 使 valueForKey:setValue:forKey: access prohibited QMUIWarnLog App
2. 使 qmui_valueForKey:qmui_setValue:forKey: valueForKey:setValue:forKey:
@link https://github.com/Tencent/QMUI_iOS/issues/617
@param key ivar 线线
@return key value key NSNumberNSValue
*/
- (nullable id)qmui_valueForKey:(NSString *)key;
/**
iOS 13 KVC 访 API access prohibited setValue:forKey: 使
iOS 12 setValue:forKey:
@note QMUI 2 access prohibited
1. IgnoreKVCAccessProhibited YES 使 valueForKey:setValue:forKey: access prohibited QMUIWarnLog App
2. 使 qmui_valueForKey:qmui_setValue:forKey: valueForKey:setValue:forKey:
@link https://github.com/Tencent/QMUI_iOS/issues/617
@param key ivar 线线
@return key value key NSNumberNSValue
*/
- (void)qmui_setValue:(nullable id)value forKey:(NSString *)key;
/**
key valueForKey:
@note valueForKey: key NO https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/SearchImplementation.html
*/
- (BOOL)qmui_canGetValueForKey:(NSString *)key;
/**
key setValue:forKey:
@note setter https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/SearchImplementation.html
*/
- (BOOL)qmui_canSetValueForKey:(NSString *)key;
@end
@interface NSObject (QMUI_DataBind)
/**
使 object nil key
@attention strong
@note 使 objc_setAssociatedObject / objc_getAssociatedObject
@code
- (UITableViewCell *)cellForIndexPath:(NSIndexPath *)indexPath {
// 1)在这里给 button 绑定上 indexPath 对象
[cell qmui_bindObject:indexPath forKey:@"indexPath"];
}
- (void)didTapButton:(UIButton *)button {
// 2)在这里取出被点击的 button 的 indexPath 对象
NSIndexPath *indexPathTapped = [button qmui_getBoundObjectForKey:@"indexPath"];
}
@endcode
*/
- (void)qmui_bindObject:(nullable id)object forKey:(NSString *)key;
/**
使 qmui_bindObject:forKey: strong object
*/
- (void)qmui_bindObjectWeakly:(nullable id)object forKey:(NSString *)key;
/**
使 bind
*/
- (nullable id)qmui_getBoundObjectForKey:(NSString *)key;
/**
double 使
*/
- (void)qmui_bindDouble:(double)doubleValue forKey:(NSString *)key;
/**
bindDouble:forKey:
*/
- (double)qmui_getBoundDoubleForKey:(NSString *)key;
/**
BOOL 使
*/
- (void)qmui_bindBOOL:(BOOL)boolValue forKey:(NSString *)key;
/**
bindBOOL:forKey:
*/
- (BOOL)qmui_getBoundBOOLForKey:(NSString *)key;
/**
long 使
*/
- (void)qmui_bindLong:(long)longValue forKey:(NSString *)key;
/**
bindLong:forKey:
*/
- (long)qmui_getBoundLongForKey:(NSString *)key;
/**
使 bind
*/
- (void)qmui_clearBindingForKey:(NSString *)key;
/**
使 bind
*/
- (void)qmui_clearAllBinding;
/**
key key
@note
*/
- (NSArray<NSString *> *)qmui_allBindingKeys;
/**
key
*/
- (BOOL)qmui_hasBindingKey:(NSString *)key;
@end
@interface NSObject (QMUI_Debug)
/// 获取当前对象的所有 @property、方法,父类的方法也会分别列出
- (NSString *)qmui_methodList;
/// 获取当前对象的所有 @property、方法,不包含父类的
- (NSString *)qmui_shortMethodList;
/// 获取当前对象的所有 Ivar 变量
- (NSString *)qmui_ivarList;
@end
@interface NSThread (QMUI_KVC)
/// 是否将当前线程标记为忽略系统的 KVC access prohibited 警告,默认为 NO,当开启后,NSException 将不会再抛出 access prohibited 异常
/// @see BeginIgnoreUIKVCAccessProhibited、EndIgnoreUIKVCAccessProhibited
@property(nonatomic, assign) BOOL qmui_shouldIgnoreUIKVCAccessProhibited;
@end
NS_ASSUME_NONNULL_END