gpt4 book ai didi

ios - NSRange 奇怪的行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:22 33 4
gpt4 key购买 nike

我的设备 (iPhone iOS 4.3) 上有奇怪的 NSRange 行为。此代码在设备和模拟器上有不同的行为。

for (Location *location in locationArray)
{
NSRange range1 = [location.name rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSRange range2 = [location.streetAddress rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSRange range3 = [location.postalCode rangeOfString:searchText options:NSCaseInsensitiveSearch];

if (range.length1 > 0 | range2.length > 0 | range3.length > 0)
[self.filteredList addObject:location];
}

如果某些属性的值范围为 nil。该属性的长度在设备上等于 2,在模拟器中等于零。

我做错了什么吗?

最佳答案

The Objective-C Programming Language

The value returned from a message to nil may also be valid:

  • If the method returns an object, then a message sent to nil returns 0 (nil). For example: Person *motherInLaw = [[aPerson spouse] mother]; If the spouse object here is nil, then mother is sent to nil and the method returns nil.
  • If the method returns any pointer type, any integer scalar of size less than or equal to sizeof(void*), a float, a double, a long double, or a long long, then a message sent to nil returns 0.
  • If the method returns a struct, as defined by the Mac OS X ABI Function Call Guide to be returned in registers, then a message sent to nil returns 0.0 for every field in the struct. Other struct data types will not be filled with zeros.
  • If the method returns anything other than the aforementioned value types, the return value of a message sent to nil is undefined.

它适用于 Mac OS X,但我认为可以肯定地说,如果消息目标为 nil,您不应该依赖返回的结构值。

关于ios - NSRange 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5275201/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com