CLLocation,获取新位置
在《更多 iPhone 编程》一书中,作者是这样做的:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if ([newLocation.timestamp timeIntervalSince1970] < [NSDate timeIntervalSinceReferenceDate] - 60)
locationCoordinate = newLocation.coordinate;
return;
...
确保数据是在最后一刻获取的。两个问题:
1)if 语句是做什么的。看起来在左侧,您得到了此方法触发时与 1970 年日期之间的时间差(以秒为单位)。然后在右侧,您会看到 2001 年日期与现在的日期之间的秒差(负 60 秒)。所以对我来说, if 语句永远不会有效,因为左边的数据总是更长的秒数。还是我理解错了?
2)void函数中的return有什么作用?这在这里被认为是好的编码吗?谢谢。
In More iPhone Programming book, the author does:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if ([newLocation.timestamp timeIntervalSince1970] < [NSDate timeIntervalSinceReferenceDate] - 60)
locationCoordinate = newLocation.coordinate;
return;
...
To make sure the data was taken in the last minute. Two questions:
1) What is the if statement doing. It seems like on the left hand side, you are getting the time difference in seconds between when this method fires and the 1970 date. Then on the right hand side, you get the difference in seconds between the 2001 date and now minus 60 seconds. So to me, the if statement would never be valid since the data on the left is always going to be a greater amount of seconds. Or am I understanding it wrong?
2) What does return in a void function do? Is that considered good coding here? Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这里发生了什么,它的语句令人困惑,我使用了类似的东西
将 return 放在 void 方法中是正确的,因为我不想在某些条件下执行接下来的语句..相同的代码可以这样写,因为
它仅取决于您的需要。
I don't know what is going on here, its confusing statement, I have use something like this
It is right to put return in void method, as I don't want to execute the statement next for some conditions..the same code can be written as
it just depends upon your need.
对于 if 块:
timeIntervalSinceReferenceDate
返回的值可能为负。参见说明。因此 if 条件可能为 false。
对于 return 语句。
如果您希望函数在到达某些 上的函数闭括号之前将控制权返回给调用函数条件。参见例如。
for the if block :
the value return by
timeIntervalSinceReferenceDate
could be negative. see the description .So if condition could be false.
For the return statement.
if you want your function to return the control to the calling function before reaching the function closed bracket on some condition. See the eg.