0
我想創建一個對實現協議的對象的引用。這是一個示例代碼:Objective-C引用實現協議的對象
@interface TestClass()
@property id <TestProtocol> testProperty;
@end
@implementation TestClass
+(id)init :(id <TestProtocol> test)
{
TestClass *testClass = [[TestClass alloc] init];
testClass.testProperty = test;
return testClass;
}
@end
然後創建一個實現協議或引用的測試對象的副本嗎?我想知道,因爲沒有「*」號。如果它是一個副本,那麼我如何創建一個參考呢?
問題似乎有點不清楚。你能提供一些關於你想用這段代碼實現什麼的更多信息嗎? id是任何類的對象的**引用**。在這種情況下「*」是隱含的。我建議你使用-initWithTest:命名。 – NKorotkov