iPhone 应用程序中的私有 API 是由什么构成的?
我对 Objective-C 相当陌生,并且对“私有 API”下的内容感到困惑,这可能会导致 Apple 拒绝我的应用程序。这是否包括向现有类添加方法?例如,我在 stackoverflow 上找到了一些代码,通过 UITabBarItem 类的扩展来重新着色 UITabBars 的选项卡栏图标。这是否被视为“私有 API”?如果不是,那是什么?
@interface UITabBar (ColorExtensions)
- (void)recolorItemsWithImage:(UIImage *)image shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;
@end
I'm fairly new to Objective-C and am confused on what falls under the unbrella of a "private API" that could cause Apple to reject my app. Does this include adding methods to existing classes? For example, I found some code on stackoverflow to recolor the tab bar icons for UITabBars with this extension to the UITabBarItem class. Is this considered a "private API"? If not, what does?
@interface UITabBar (ColorExtensions)
- (void)recolorItemsWithImage:(UIImage *)image shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的内容可能是 Objective-C 类别< /a> 使用新方法扩展了
UITabBar
类。这完全是犹太洁食。您甚至可以使用类别覆盖现有方法,但不建议这样做。一般来说,私有方法前面通常会带有下划线。您也不想使用 Apple 为大型 UI 对象保留的私有类,例如
UIWebView
中的私有组件。您不想使用这些,否则您的应用程序将被拒绝。您在项目框架的头文件中看到的任何内容都是“公共”且可用的。无论如何,如果您确实想了解有关该类的所有内容,那么浏览标题是个好主意。
The above is probably an Objective-C category that extends the
UITabBar
class with new methods. This is perfectly kosher. You can even overwrite existing methods with categories, although this isn't recommended.In general, private methods will often have underscores in front of them. You also don't want to use private classes that Apple reserves for large UI objects, such as the private components within a
UIWebView
. You don't want to use these or your app will get rejected.Anything that you see in a header file in the Frameworks in your project is "public" and usable. It's a good idea to thumb through the header if you really want to know everything about the class, anyway.
不,由用户代码添加的类别不是“私有的”。私有 API 是 Apple 的内部 API,没有文档记录。如果方法不在头文件中并且不在开发人员文档中,则它们是私有的。 (根据经验,如果您没有收到任何编译器警告,则您没有使用私有 API。)
No, categories added by user code are not "private." Private APIs are Apple's internal APIs, which are undocumented. Methods are private if they aren't in the header files and aren't in the developer documentation. (As a rule of thumb, if you don't get any compiler warnings, you aren't using private APIs.)