NSRange 奇怪的行为
我的设备(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];
}
如果某些属性的 range.lenght 值为零,则该属性在设备上等于 2,在模拟器中等于 0。
我做错了什么吗?
I have strange NSRange behavior on my device (iPhone iOS 4.3). This code has a different behavior on device and simulator.
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];
}
If some of properties has nil value range.lenght for that property is equal to 2 on device and zero in simulator.
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Objective-C 编程语言
它适用于 Mac OS X,但我认为可以肯定地说,如果消息目标为 nil,则不应依赖返回的结构值。
The Objective-C Programming Language
It's for Mac OS X but I think it's safe to say that you should not rely on returned struct values if message target is nil.