Mac App Store 是否允许子类化私有方法?
Mac App Store 指南指出:
使用非公共 API 的应用将被拒绝
这是否包括使用其类参考中未提及的方法对公共对象进行子类化?
The Mac App Store guidelines state:
Apps that use non-public APIs will be rejected
Does that include sub-classing public objects with methods that aren't mentioned in their class' reference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
苹果在这方面并没有完全一致,但他们为此拒绝了一些应用程序。
Apple has not been entirely consistent in this regard, but they have rejected some apps for this.
我强烈建议不要这样做。你不知道苹果是否会拒绝你的应用程序(所以你必须返回并修复它),或者他们是否会更改私有方法(也许它将来不会存在,所以你的应用程序将无法运行)正如未来 OS X 版本的预期(这也适用于 iOS),然后您将不得不返回并修复它)。
不管怎样,无论他们批准还是拒绝你的应用程序,这都是一个坏主意。
你到底想做什么?也许有更好、更安全的方法来做到这一点。
I would strongly recommend against it. You don't know if Apple will reject your app for it (so you have to go back and fix it), or if they will change the private method (maybe it won't exist in the future so your apps won't work as expected on future OS X versions (this applies to iOS as well), and then you will have to go back and fix it).
Either way, whether they approve or reject your app, it's a bad idea.
What are you trying to do exactly anyway? Maybe there is a better and safer way to do it.
几乎所有(但最简单的)设计良好的对象都会有私有 API。这就是封装的全部思想。
我的猜测是,当您对框架类进行子类化时,您的代码仍然只调用该类上的公共 API,因此您自己不会调用任何私有 API。如果不是这种情况,那么肯定没有人能够使用 Cocoa 和 Cocoa-touch 框架发布任何软件。
如果您子类化并故意调用私有方法,那么这当然是一种违规。
以这个例子为例,
如果我这样做,
save 方法会导致私有 API 方法
- (void)doSomeWork;
被调用。我没有直接调用框架类。如果我这样做了,那么我将直接调用私有 API,这将被拒绝。
Almost all (but the simplest) well designed object's will have have private API's. That is the whole idea of encapsulation.
My guess is that when you sub-class a framework class, your code is stil only calling the public API on that class therefore you are not yourself calling any private API's. If this was not the case then surely no one would be able to release any software using the Cocoa and Cocoa-touch frameworks.
If you subclass and deliberately call a private method then of course this would be a violation
Take this example
If I do this
the save method results in the private API method
- (void)doSomeWork;
being called. I did not call it directly the framework class did. If I had done this insteadThen I would be calling the private API directly which would be declined.