对不起我的疯狂需求,但我在我写的框架中创建了一堆属性专用协议。“模拟”一个实现属性专用协议的对象的最简单方法
@protocol SomePropertiesOfAnObjectThing <NSObject>
@property (nonatomic, strong) NSString *larry;
@property (nonatomic, strong) NSString *curly;
@property (nonatomic, strong) NSString *moe;
@end
有没有一种方法,更重要的是一种简单的方法来“模拟”一个实现此协议的对象?
id<SomePropertiesOfAnObjectThing> thingy = [ProtocolObject fromProtocol:@protocol(SomePropertiesOfAnObjectThing)];
thingy.larry = @"fizz";
thingy.curly = @"buzz";
thingy.moe = @"bar";
的两件事情,我试图避免:
- 显式地创建一个新的类
- 第三方的依赖(如OCMock)
我洗澡的人谁可以用最多的选票向我展示干净而简单的方式(至少1)。
我说OCMock完成了这个。我正在寻找一个不涉及复制整个框架的解决方案。 –
没关系,我告诉你单靠协议无法做到这一点。 –