本文主要是介绍【Foundation-86-2】#import Foundation/NSValue.h,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@interface NSValue (NSValueExtensionMethods)
// 封装 弱引用的类(不知道用那里)0.0
+ (NSValue *)valueWithNonretainedObject:(id)anObject;
@property (nonatomic, readonly) id nonretainedObjectValue;
// button 是一个 obj(假设是弱引用)__weak UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];button.backgroundColor = [UIColor redColor];[button setFrame:CGRectMake(111, 111, 111, 111)];// value objNSValue *value = [NSValue valueWithNonretainedObject:button];[array addObject:value];NSValue *newValue = [array objectAtIndex:0];[self.view addSubview:(UIButton *)[newValue nonretainedObjectValue]];
//封装 对象的指针
+ (NSValue *)valueWithPointer:(const void *)pointer;
- (void *)pointerValue;
NSValue* start = [NSValue valueWithPointer:@selector(start)];[start pointerValue]; //就对应了 @selector(start);UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[button setFrame:CGRectMake(111, 111, 111, 111)];button.backgroundColor = [UIColor redColor];[self.view addSubview:button];[button addTarget:self action:[start pointerValue] forControlEvents:UIControlEventTouchUpInside];}-(void)start{NSLog(@"11");
}
//判断 2 个value 是否一致
- (BOOL)isEqualToValue:(NSValue *)value;
NSValue *value1 = [NSValue valueWithCGSize:CGSizeMake(11, 11)];NSValue *value2 = [NSValue valueWithRange:NSMakeRange(11, 11)];if ([value1 isEqualToValue:value2]) {NSLog(@"same");}else{NSLog(@"different");}
@end
这篇关于【Foundation-86-2】#import Foundation/NSValue.h的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!