gpt4 book ai didi

objective-c - 对指向接口(interface) 'NSDate' 的指针进行算术运算,这在非脆弱 ABI 中不是常量大小

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:08 24 4
gpt4 key购买 nike

下一个obj-c代码有问题错误。

if (fabs(originalLocation.timestamp - ((CLLocation *)[lastLocations objectAtIndex:i]).timestamp) > constAverageLocationTimeout) 
{
//do
}

xCode 发送错误:

error: Semantic Issue: Arithmetic on pointer to interface 'NSDate', which is not a constant size in non-fragile ABI

有什么想法吗?

最佳答案

如果你把它分解一点,你的程序(和编译器错误的位置)会更有意义。也许是这样的:

NSDate * orginalDate = originalLocation.timestamp;
CLLocation * lastLocation = [lastLocations objectAtIndex:i];
NSDate * lastDate = lastLocation.timestamp;

NSTimeInterval originalTime = [originalDate timeIntervalSinceReferenceDate];
NSTimeInterval lastTime = [lastDate timeIntervalSinceReferenceDate];
NSTimeInterval elapsed = fabs(originalTime - lastTime);

if (elapsed > constAverageLocationTimeout) {
/* do */
}

具体来说,timestampNSDate 类型的属性,而不是 NSTimeInterval 等标量数。

关于objective-c - 对指向接口(interface) 'NSDate' 的指针进行算术运算,这在非脆弱 ABI 中不是常量大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7306852/

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