我有一个想要使用CLLocationManager及其某些委托方法的类方法.
从类方法访问委托方法的最佳方法是什么,因为我没有真正的实例级别"self"?我可以实例化一个self并将其用作委托,这将使委托方法运行,但不会显示如何获取数据.什么是最好的方法?
// desired end function, which runs a block when location is found
[SFGeoPoint geoPointForCurrentLocationInBackground:^(SFGeoPoint *geoPoint, NSError *error) {
if (!error) {
// do something with the new geoPoint
NSLog(@"GeoPoint: %@", geoPoint);
}
}];
// SFGeoPoint class, key points
static CLLocationManager *_locationManager = nil;
// get geo point for current location and call block with it
+ (void) geoPointForCurrentLocationInBackground:( void ( ^ )( SFGeoPoint*, NSError* ) ) locationFound {
SFGeoPoint *point = [[SFGeoPoint alloc] init];
_locationManager = [[CLLocationManager alloc] …Run Code Online (Sandbox Code Playgroud) 在我的Iphone应用程序中,我之前通过执行以下代码将标准plist文件加载到Dictionary中.最近我将源文件和plist文件复制到一个新的包中,我将其编译成一个框架并在原始应用程序中使用.所有代码都在运行,但plist加载代码无法再找到settings.plist文件.看看路径,它似乎仍然在查看主应用程序的文件.
我是否需要以某种方式更新此捆绑包以读取嵌入式资源的框架?
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [[bundle resourcePath] stringByAppendingPathComponent:@"settings.plist"];
_plistDictionary = [[NSDictionary alloc] initWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 NSDateComponents 来测试动态日期是否发生在“今天”。我用它来提取年/月/日,然后比较两个 NSDate 的这些值。理论上这应该有效。我在东海岸,所以东部时间,与 UTC 的距离为 -5。
当前实际时间:12:40:53,美国东部时间
以下是正确的 NSDate(UTC 时间)。时间是正确的 UTC:
这是我的日志,显示了每个日期。它将日期转换为本地时区 2016-01-19 07:00:00。由于当前日期位于一天中,因此 -5 小时偏移量不会导致日期发生变化。然而,午夜的时间却回到了一天前。我怎样才能让它尊重UTC?
NS日志:
2016-1-19 12:40:53 (America/New_York (EST) offset -18000),
2016-1-18 19:0:0 (America/New_York (EST) offset -18000)
Run Code Online (Sandbox Code Playgroud)
代码:
NSDateComponents *current = [[NSCalendar currentCalendar] components:NSCalendarUnitEra | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond |NSCalendarUnitTimeZone fromDate:_date];
NSDateComponents *activity = [[NSCalendar currentCalendar] components:NSCalendarUnitEra | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond |NSCalendarUnitTimeZone fromDate:activityModel.date];
// …Run Code Online (Sandbox Code Playgroud) 我第一次使用GTFS结构并且遇到查询问题.我已经将传输数据传输到mysql表中,并且可以自由地查询它们,但我觉得我做了太多的查询和循环来获取最简单的信息.
我想在单个查询中获得的是两个已知停靠点之间的所有出发时间和到达时间,可能通过名称识别.
这是我到目前为止所涉及的问题,其中涉及查询,然后循环遍历每个trip_id以查找出发和到达站信息+次.
查询1:
显示特定始发站的所有出发时间,沿特定方向行驶.结果将给出出发时间和trip_ids.
SELECT t.trip_id, trip_headsign, departure_time, direction_id, s.stop_name
FROM stops s, routes r, stop_times st, calendar c, trips t
WHERE departure_time > "00:00:00" and departure_time < "23:59:59"
AND r.route_id=1 and s.stop_id = 42
AND s.stop_id = st.stop_id
AND st.trip_id = t.trip_id
AND c.service_id = t.service_id
AND c.monday=1 and direction_id=1;
Run Code Online (Sandbox Code Playgroud)
结果
+---------+---------------+----------------+--------------+-----------+
| trip_id | trip_headsign | departure_time | direction_id | stop_name |
+---------+---------------+----------------+--------------+-----------+
| 5671498 | Grand Central | 04:43:00 | 1 | Garrison |
| …Run Code Online (Sandbox Code Playgroud)