Following problem: I receive an Object from a framework (which is not instantiable) and I want to extend it. When I make a category, the problem is, that it doesn't have an effect on the existing object.
I thought of isa swizzling. So let the isa field point to the extended "list of selectors". But that doesn't seem to be possible? (Syntax for it?)
Does anyone know a better approach to do it ?
That is the code:
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray<CBATTRequest *> *)requests {
//want to do something that uses the extension
}
And I want to extend CBATTRequest. I think the problem lies in CoreBluetooth?
This is how I make my category:
BLERequestable.h
@protocol BLERequestable <NSObject>
- (nonnull NSString *)getCentralUUID;
- (nonnull NSString *)getCharacteristicUUID;
- (nullable NSData*)getData;
- (void)setData:(nullable NSData *) data;
@end
CBATTRequest+Requestable.h
#import <CoreBluetooth/CoreBluetooth.h>
#import "BLERequestable.h"
@interface CBATTRequest (Requestable) <BLERequestable>
@end
CBATTRequest+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
And I import the Category everywhere I want to use it.