Mac App Store 是否允许子类化私有方法?

发布于 2024-11-29 19:40:42 字数 119 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泅人 2024-12-06 19:40:42

苹果在这方面并没有完全一致,但他们为此拒绝了一些应用程序。

Apple has not been entirely consistent in this regard, but they have rejected some apps for this.

樱&纷飞 2024-12-06 19:40:42

我强烈建议不要这样做。你不知道苹果是否会拒绝你的应用程序(所以你必须返回并修复它),或者他们是否会更改私有方法(也许它将来不会存在,所以你的应用程序将无法运行)正如未来 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.

唔猫 2024-12-06 19:40:42

几乎所有(但最简单的)设计良好的对象都会有私有 API。这就是封装的全部思想。

我的猜测是,当您对框架类进行子类化时,您的代码仍然只调用该类上的公共 API,因此您自己不会调用任何私有 API。如果不是这种情况,那么肯定没有人能够使用 Cocoa 和 Cocoa-touch 框架发布任何软件。

如果您子类化并故意调用私有方法,那么这当然是一种违规。

以这个例子为例,

/*
 * This is a framework class that needs to be subclassed
 * it has one public method  - (void)save;
 * and one private method    - (void)doSomeWork;
 */
@interface FrameWorkClass : NSObject

- (void)save;

@end

@interface FrameWorkClass ()

//private 
- (void)doSomeWork;

@end

@implementation FrameWorkClass

- (void)save
{
  [self doSomeWork]; // Call to private method
}

@end

/*
 * This is our subclass of FrameWorkClass
 */
@interface MyClass : FrameWorkClass
// more methods
@end

如果我这样做,

MyClass *myClass = [[MyClass alloc] init];
[myClass save];

save 方法会导致私有 API 方法 - (void)doSomeWork; 被调用。我没有直接调用框架类。如果我这样做了

MyClass *myClass = [[MyClass alloc] init];
[myClass 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

/*
 * This is a framework class that needs to be subclassed
 * it has one public method  - (void)save;
 * and one private method    - (void)doSomeWork;
 */
@interface FrameWorkClass : NSObject

- (void)save;

@end

@interface FrameWorkClass ()

//private 
- (void)doSomeWork;

@end

@implementation FrameWorkClass

- (void)save
{
  [self doSomeWork]; // Call to private method
}

@end

/*
 * This is our subclass of FrameWorkClass
 */
@interface MyClass : FrameWorkClass
// more methods
@end

If I do this

MyClass *myClass = [[MyClass alloc] init];
[myClass save];

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 instead

MyClass *myClass = [[MyClass alloc] init];
[myClass doSomeWork];

Then I would be calling the private API directly which would be declined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文