2012-02-10 84 views
1

我想禁止一些方法。例如有没有一种简单的方法来禁止框架中的某种方法?

+ (MPMusicPlayerController*)iPodMusicPlayer 

所以我尝试这样做:

@interface MPMusicPlayerController (Disallowed) 
// do never this method cause issues #957 #632 #1463 
// read #632 description to detail analysis why code should never use this method while 
// applicationMusicPlayer is used 
+ (MPMusicPlayerController*)iPodMusicPlayer __attribute__((unavailable)); 
+ (MPMusicPlayerController*)iPodMusicPlayer __attribute__((deprecated)); 
@end 

,但下面的代码编译反正没有任何警告

MPMusicPlayerController * curPlayer = [MPMusicPlayerController iPodMusicPlayer]; 

有什么想法?

+0

我很难想象这种情况下,这将是适当的解决方案的问题。 – UIAdam 2012-02-10 04:11:36

回答

2

编译时的解决方案:

一种方法,只需要使用下面的代码:

#pragma GCC poison iPodMusicPlayer 

我应该提到SDK61和SDK7不能 '毒药' 选择含有 ':' 导致llvm bug :(

另一种方式:

1

我想你可以在MPMusicPlayerController上创建一个类别,例如,覆盖(MPMusicPlayerController + Override),然后覆盖iPodMusicPlayer类的方法返回nil。一定要#include MPMusicPlayerController + Override.h。

您可以添加警告标志,以你的方法,提醒人不要使用它:

#warning Disabled method - do not use. 

请让我知道这是否为你的作品。

达明

+0

谢谢。该方法是运行时解决方案。但编译时解决方案是preffer。 – Speakus 2012-02-10 04:34:20

相关问题