問題在標題中。代碼示例:Objective-C - 如何隱藏實現協議的類的方法
UIViewController <MyProtocol> *viewcontroller = ...;
[viewcontroller methodFromProtocol]; // I expect to be able to call all methods that the protocol defines
//UIViewControllerSubclass implements MyProtocol
UIViewControllerSubclass *viewControllerSubclassWithoutMyProtocol = [[UIViewControllerSubclass alloc] init];
[viewControllerSubclassWithoutMyProtocol methodThatIsNotInTheInterfaceIsDisplayedHere]; // I only expect to be able to call the methods that are defined in this class' interface even though this class implements MyProtocol
感謝這似乎做了工作的「部分」:)現在,如果我只想要協議定義的一些methodos只能從實現協議的類內部訪問並且不在類之外顯示。這可能嗎? – 2012-07-13 14:36:10
定義「可見」?關於爲什麼這類事情不經常完成的信息,請參閱Amy Worral的出色答案。你想達到什麼目的? – jrturton 2012-07-13 14:42:54
如果我嘗試在沒有「」的情況下訪問該類,則可以看到Xcode不會顯示協議方法的自動完成。我想要實現的是讓一些類實現協議方法,我希望我的所有類都可以在最低限度上實現。然後這些類實現的這些方法中的一些只能從類本身調用。換句話說,我想要實現與在接口中聲明「public」方法相同的功能,然後在實現中聲明僅在此類中使用的方法。 –
2012-07-13 14:47:40