NSNotFound的可用性是多少? [英] What is the availability of NSNotFound?

查看:346
本文介绍了NSNotFound的可用性是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSNotFound 的这个in-Xcode文档非常令人困惑:

This in-Xcode documentation for NSNotFound is quite confusing:

它表示适用于iOS 2.0到8.4和可用性:iOS 8.1到8.0。那么...... 8.0之前可用吗?还是9.0+?此外,这里发生了什么,如果是的话?

It says "Available in iOS 2.0 through 8.4" and "Availability: iOS 8.1 to 8.0". So... Is it available before 8.0? Or in 9.0+? Also, what's going on here, if it is?

推荐答案

插入 availabilityOfNSNotFound == NSNotFound 在这里开玩笑。

Apple正在推动强制性的64位设备支持(iOS 8.4 SDK?), NSNotFound 的声明已更改为:

At some point when Apple was pushing mandatory 64-bit device support (iOS 8.4 SDK?), the declaration of NSNotFound was changed from:

enum {NSNotFound = NSIntegerMax};

static const NSInteger NSNotFound = NSIntegerMax;

您可以在< Foundation / NSObjCRuntime.h>

文档从未更改过,因此枚举的可用性 NSNotFound 不再在SDK中。但是从iOS 9及更高版本开始, static const NSInteger NSNotFound 可用。

The documentation was never changed, so the availability of the enum NSNotFound is no longer in the SDK. But as of iOS 9 and above, the static const NSInteger NSNotFound is available.

虽然我无法回答 NSNotFound 的真实可用性,因为我不适合Apple(作为开发人员,我认为在所有iOS中使用都是安全的)自2.0以来的版本,或者很多基础类会因为返回 NSNotFound 而中断,你可以查看 NSNotFound的内存位置为NULL:

Although I cannot answer the true availability of NSNotFound since I don't work for Apple (as a developer I think it's safe to use in all iOS versions since 2.0, or else a lot of Foundation classes would break since they can return NSNotFound), you can check to see if the memory location for NSNotFound is NULL:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
BOOL found = (&NSNotFound != NULL);
#pragma clang diagnostic pop
if (found) {
    NSLog(@"meh");
}

这篇关于NSNotFound的可用性是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆