我正在努力的代码,以获得用户的位置和卡住

First please take a look at codes below

CoreLocationController.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@protocol CoreLocationControllerDelegate     // Line 1
@required                       

- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;

@end

/* Declare class named CoreLocationControll and inherited from CLLocationManagerDelegate */
@interface CoreLocationController : NSObject <CLLocationManagerDelegate> {
    CLLocationManager *locMgr;
    id delegate;
}

@property (nonatomic, retain) CLLocationManager *locMgr;            // claim setter and getter for locMgr
@property (nonatomic, assign) id delegate;                          // claim setter and getter for delegate

@end


CoreLcationController.m
#import "CoreLocationController.h"

@implementation CoreLocationController
@synthesize locMgr, delegate;

/* Is triggered by - (void)startUpdatingLocation from CoreLocationDemoViewController.m*/
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"CORE_LOCATION_CONTROLLER=======>DID_UPDATE_TO_LOCATION");
    if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) // line 2
        [self.delegate locationUpdate:newLocation];

}

My questions are what line 1 and line 2 do and why I looked up CoreLocationControllerDelegate but no reference on it

#0

The lines you are asking about are objective-c protocol declarations. The code is declaring a protocol called CoreLocationControllerDelegate. A protocol is, in simple terms, a list of methods that, a given object can be expected to implement if it conforms to the protocol.

For example, the UITextFieldDelegate protocol contains the various methods that an object should or must implement if it wants to be the delegate for a text field.

Line 1 @required means that the object has to implement the following methods to conform to the protocol. If you declare your object as conforming to the protocol, it must implement those methods or you will get build errors (or warnings, I can't remember which).

Line 2 is a safety check to make sure that the delegate conforms to the protocol (in this case, that it implements the required methods) before the delegate methods are called. This prevents a runtime crash where an unrecognised selector is sent to the object.

推荐文章

在JBossWS中使用用户名令牌时,如何从内存中删除密码?

在JBossWS中使用用户名令牌时,如何从内存中删除密码?

推荐文章

在django中运行普通sql查询时如何获取字段名

在django中运行普通sql查询时如何获取字段名

推荐文章

如何直接访问github的html项目

如何直接访问github的html项目

推荐文章

asp.net:如何将类似LinkButton的链接功能与表单元格背景上的委托关联起来?

asp.net:如何将类似LinkButton的链接功能与表单元格背景上的委托关联起来?

推荐文章

net写的ajax无刷新分页

net写的ajax无刷新分页

推荐文章

在unix(firefox)中通过javascript读取变量中的html文件

在unix(firefox)中通过javascript读取变量中的html文件

推荐文章

创建值为Action实例的字典的语法是什么?

创建值为Action实例的字典的语法是什么?

推荐文章

VUE单元测试:vue-jest-unit-test

VUE单元测试:vue-jest-unit-test

推荐文章

为什么WPF中的所有内容都是模糊的?

为什么WPF中的所有内容都是模糊的?

推荐文章

对于64K的数据,GZIP压缩不起作用

对于64K的数据,GZIP压缩不起作用

推荐文章

浮动时出现奇怪的div边界问题

浮动时出现奇怪的div边界问题

推荐文章

Php文件加密方法。有简单的东西存在吗?

Php文件加密方法。有简单的东西存在吗?

推荐文章

写一篇大家一看就会的教程《JNI初步》

写一篇大家一看就会的教程《JNI初步》

推荐文章

将多个节添加到App.Config

将多个节添加到App.Config

推荐文章

Windows函数

Windows函数

推荐文章

java xmltojson jsontoxml

java xmltojson jsontoxml