下面的问题:我从一个框架收到一个对象(它不是实例化的),我想扩展它。当我创建一个类别时,问题是,它对现有的对象没有影响。
我想到了isa swizzling。因此,让isa字段指向扩展的“选择器列表”。但这似乎是不可能的?(它的语法?)
有没有人知道更好的方法呢?
这就是代码:
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray<CBATTRequest *> *)requests {
//want to do something that uses the extension
}我想扩展CBATTRequest。我认为问题出在CoreBluetooth?
这是我如何创建我的类别:
BLERequestable.h
@protocol BLERequestable <NSObject>
- (nonnull NSString *)getCentralUUID;
- (nonnull NSString *)getCharacteristicUUID;
- (nullable NSData*)getData;
- (void)setData:(nullable NSData *) data;
@endCBATTRequest+Requestable.h
#import <CoreBluetooth/CoreBluetooth.h>
#import "BLERequestable.h"
@interface CBATTRequest (Requestable) <BLERequestable>
@endCBATTRequest+Requestable.m
#import "CBATTRequest+Requestable.h"
@implementation CBATTRequest (Requestable)
- (NSString *)getCentralUUID {
return self.central.identifier.UUIDString;
}
- (NSString *)getCharacteristicUUID {
return self.characteristic.UUID.UUIDString;
}
- (NSData*)getData {
return self.value;
}
- (void)setData:(NSData *) data {
self.value = data;
}
@end我将Category导入到我想要使用的任何地方。
https://stackoverflow.com/questions/47816257
复制相似问题